안녕하세요. ManVSCloud 김수현입니다.
오늘은 2021-01-07에 나온 PHP 8.0.1 버전을 컴파일 설치해보려고 합니다.

테스트는 WordPress까지 연동하여 정상적으로 플러그인 설치 및 글쓰기가 되는지까지 확인할 것입니다.
Environment
CentOS Linux release 7.7.1908 (Core) x86_64
CPU : Intel(R) Xeon(R) CPU E5-2686 v4 @ 2.30GHz (4core)
Memory : 16G
(PHP 컴파일 시 out of memory 발생하여 인스턴스 크기를 m4.xlarge로 하여 테스트 했습니다.)
Apache : httpd-2.4.6-97.el7.centos.x86_64
PHP : PHP 8.0.1 (cli)
MariaDB : MariaDB-server-10.4.17-1.el7.centos.x86_64
WordPress : 5.6
Apache와 MariaDB는 RPM으로 설치하였습니다.
Basic Install & Setting

1 cat -n /etc/selinux/config 2 sed -i '7s/enforcing/disabled/g' /etc/selinux/config 3 yum install gcc gcc* make cmake libtool wget zip unzip autoconf automake libjpeg-devel libpng-devel freetype-devel libxml2-devel libicu* hspell libvoikko enchant-devel libffi-devel libcurl-devel libldap* sqlite-devel "Image*" *imap-devel pam-devel openssl-devel firebird-devel aspell-devel readline-devel net-snmp-devel libsodium-devel yum install libtidy libtidy-devel libxslt-devel git bzip2-devel #(위에서 설치가 안될 수도 있습니다. 이후 epel 추가 후 재설치하면 나머지가 설치됩니다.) 4 init 6
원활한 설치를위해 selinux 기능을 꺼주고 기본 라이브러리들을 설치해준 뒤
재시작을 해줍니다.
(기본 라이브러리는 사용하실 부분만 골라서 설치하셔도 됩니다.)
Apache & MariaDB Install
[Apache]
yum install httpd httpd-devel -y cp -avp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf_org #[root@ip-10-0-1-238 conf]# cat -n /etc/httpd/conf/httpd.conf | grep Indexes #135 # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews #144 Options Indexes FollowSymLinks sed -i '144s/Indexes//g' /etc/httpd/conf/httpd.conf #(144번줄에 있는 Indexes를 제거해주도록 하겠습니다.) #[root@ip-10-0-1-238 ~]# cat -n /etc/httpd/conf/httpd.conf | grep -A 3 "Directory /" #102 <Directory /> #103 AllowOverride none #104 Require all denied #105 </Directory> perl -p -i -e '$.==104 and print " Require all granted\n"' /etc/httpd/conf/httpd.conf sed -i '105s/ Require all denied/#&/' /etc/httpd/conf/httpd.conf #(104 번줄에 접근 허용 설정 및 denied 부분은 주석 처리해주겠습니다.) #[root@ip-10-0-1-238 ~]# cat -n /etc/httpd/conf/httpd.conf | grep -A 4 "Directory /" #102 <Directory /> #103 AllowOverride none #104 Require all granted #105 # Require all denied #106 </Directory> cat << EOF >> /etc/httpd/conf/httpd.conf ServerTokens Prod ServerSignature Off <IfModule mpm_prefork_module> StartServers 40 MinSpareServers 25 MaxSpareServers 100 ServerLimit 1024 MaxRequestWorkers 1024 MaxConnectionsPerChild 0 </IfModule> IndexIgnore * EOF cat /etc/httpd/conf/httpd.conf | tail -n 11 #위 명령어로 httpd.conf에 옵션이 잘 들어갔는지 확인합니다. cat << EOF > /etc/httpd/conf.d/vhost.conf <VirtualHost *:80> ServerName php.manvscloud.com DocumentRoot /home/php/wordpress/ </VirtualHost> EOF mkdir -p /home/php/wordpress apachectl -S #위 명령어로 virtual host가 정상적으로 추가되었는지 확인합니다. systemctl enable httpd systemctl start httpd
[MariaDB]
cat << EOF > /etc/yum.repos.d/MariaDB.repo [mariadb] name = MariaDB baseurl = http://yum.mariadb.org/10.4/centos7-amd64 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1 EOF yum install MariaDB-server MariaDB-client -y systemctl enable mariadb systemctl start mariadb mysql -uroot -p create database wordpress; create user 'manvscloud'@'localhost' identified by 'PW'; grant all privileges on wordpress.* to 'manvscloud'@'localhost'; flush privileges; exit
PHP 8.0.1
cd /usr/local/src
wget https://www.php.net/distributions/php-8.0.1.tar.gz
tar zxvf php-8.0.1.tar.gz
./configure –help > phpconf_help.txt
생성한 phpconf_help.txt 를 잘 읽어보자. ★★★★★
아래는 php 컴파일 중에 설치가 덜 되거나 추가로 설정해주어야하는 부분이 있어
정리해보았습니다. (oracle, postgresql 제외)
컴파일 중 oniguruma가 없다는 에러가 발생했습니다.
(No package ‘oniguruma’ found)
oniguruma-devel를 설치해주어야하는데 epel-release 설치를 하지 않고
oniguruma-devel를 설치할 경우 패키지를 찾을 수 없습니다.
(No package oniguruma-devel available.)
yum install epel-release
yum install oniguruma-devel
-. libzip
configure: error: Package requirements (libzip >= 0.11 libzip != 1.3.1 libzip != 1.7.0) were not met:No package ‘libzip’ found
CentOS7에서 libzip yum으로 설치할 경우 0.10.1-8.el7으로만 설치되어 따로 컴파일해주었습니다.
cd /usr/local/src
wget https://libzip.org/download/libzip-1.7.3.tar.gz
tar zxvf libzip-1.7.3.tar.gz
cd libzip-1.7.3
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/libzip
libzip 1.7.3 버전을 컴파일 하기위해서는 cmake 3.0.2 이상이 필요했습니다.
CMake Error at CMakeLists.txt:1 (cmake_minimum_required):
CMake 3.0.2 or higher is required. You are running version 2.8.12.2
wget https://github.com/Kitware/CMake/releases/download/v3.18.5/cmake-3.18.5-Linux-x86_64.tar.gz
tar zxvf cmake-3.18.5-Linux-x86_64.tar.gz
mv cmake-3.18.5-Linux-x86_64 /usr/local/cmake
/usr/local/cmake/bin/cmake -DCMAKE_INSTALL_PREFIX=/usr/local/libzip
make && make install
export PKG_CONFIG_PATH=/usr/local/libzip/lib64/pkgconfig
(이후 /etc/profile 에 넣어 줍시다.)
-. ldap
cp -frp /usr/lib64/libldap* /usr/lib
./configure --prefix=/usr/local/php \ --with-apxs2=/usr/bin/apxs \ --with-config-file-path=/etc/ \ --with-config-file-scan-dir=/etc/php.d \ --enable-gd \ --with-zlib \ --with-freetype \ --with-jpeg \ --with-curl \ --with-pear \ --with-openssl \ --enable-bcmath \ --with-bz2 \ --enable-calendar \ --enable-ctype \ --enable-dba \ --enable-dom \ --with-enchant \ --enable-exif \ --with-ffi \ --enable-fileinfo \ --enable-filter \ --enable-ftp \ --with-gettext \ --with-gmp \ --with-iconv \ --enable-intl \ --with-ldap \ --enable-mbstring \ --with-mysqli \ --enable-mysqlnd \ --enable-pcntl \ --enable-pdo \ --with-pdo_firebird \ --with-pdo_mysql \ --with-pdo_sqlite \ --enable-phar \ --enable-posix \ --with-pspell \ --with-readline \ --enable-session \ --enable-shmop \ --with-snmp \ --enable-soap \ --enable-sockets \ --with-sodium \ --with-sqlite3 \ --enable-sysvmsg \ --enable-sysvsem \ --enable-sysvshm \ --with-tidy \ --enable-tokenizer \ --with-xsl \ --with-zip \ --enable-simplexml \ --with-libxml \ --enable-xml \ --enable-xmlreader \ --enable-xmlwriter \ --enable-opcache
make -j `grep processor /proc/cpuinfo | wc -l` #(j옵션을 주어 컴파일 속도를 최적화 합니다.) /bin/ld: ext/ldap/ldap.o: undefined reference to symbol 'ber_memfree' #(make 중에 ldap 쪽에서 위와 같은 에러가 발생했습니다.) #(아래처럼 Makefile을 수정할 필요가 있었습니다.) vi Makefile EXTRA_LIBS = -lcrypt -ltidy -lresolv -lcrypt -lreadline -lncurses -laspell -lpspell -lfbclient -lrt -lldap -llber -lstdc++ -lgmp -lbz2 -lutil -lrt -lm -ldl -lxml2 -lssl -lcrypto -lsqlite3 -lz -lcurl -lxml2 -lenchant -lgmodule-2.0 -lglib-2.0 -lffi -lssl -lcrypto -lz -lpng15 -ljpeg -lfreetype -licuio -licui18n -licuuc -licudata -lonig -lsqlite3 -lxml2 -lnetsnmp -lssl -lssl -lcrypto -lm -lxml2 -lsodium -lxml2 -lxml2 -lxml2 -lxslt -lz -ldl -lm -lxml2 -lexslt -lxslt -lz -lm -lgcrypt -ldl -lgpg-error -lxml2 -lzip -lz -lssl -lcrypto -lcrypt #(위와 동일한 에러 발생 시 Makefile에 EXTRA_LIBS 쪽에 -llber 추가) make -j `grep processor /proc/cpuinfo | wc -l` make install cp -avp php.ini-production /etc/php.ini
cat << EOF >> /etc/profile
export PKG_CONFIG_PATH=/usr/local/libzip/lib64/pkgconfig
PATH=$PATH:/usr/local/php/bin
export PATH
EOF
source /etc/profile
< imagick 모듈 추가 >
cd /usr/local/src wget https://pecl.php.net/get/imagick-3.4.4.tgz tar zxvf imagick-3.4.4.tgz cd imagick-3.4.4 phpize ./configure --with-php-config=/usr/local/php/bin/php-config make
/usr/local/src/imagick-3.4.4/imagick_file.c:313:112: error: expected ??;??, ??,?? or ??)?? before ??TSRMLS_DC??
zend_bool php_imagick_stream_handler(php_imagick_object *intern, php_stream *stream, ImagickOperationType type TSRMLS_DC)
^
make: *** [imagick_file.lo] Error 1
(php8에서는 imagick이 정상적으로 설치가 되지않고 Error가 발생했습니다.
동일한 오류가 해외쪽에서도 있었는지 찾다보니 git에서 8버전에서 사용할 수 있는
imagick을 찾게 되었습니다.)
git clone https://github.com/Imagick/imagick.git cd imagick phpize ./configure --with-php-config=/usr/local/php/bin/php-config make mkdir -p /etc/php.d/modules cp -a /usr/local/src/imagick/modules/imagick.so /etc/php.d/modules/imagick.so
< opcache 모듈 설치 >
컴파일 시 추가했던 opcache가 자동으로 올라오지 않아 수동으로 추가해주었습니다.
cd /usr/local/src/php-8.0.1/ext/opcache phpize ./configure --with-php-config=/usr/local/php/bin/php-config make cp -a /usr/local/src/php-8.0.1/ext/opcache/modules/opcache.so /etc/php.d/modules/opcache.so
(php.ini에 imagick과 opcache 모듈을 추가 해줍니다.)
cat << EOF >> /etc/php.ini
extension=/etc/php.d/modules/imagick.so
zend_extension=/etc/php.d/modules/opcache.so
EOF
마지막으로 httpd.conf에 아래 값을 추가 한 뒤 마무리합니다.
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
AddType application/x-httpd-php .php .htm .html .inc
AddType application/x-httpd-php-source .phps
WordPress Install & TEST
cd /home/php
wget https://ko.wordpress.org/latest-ko_KR.tar.gz
tar zxvf latest-ko_KR.tar.gz
cd wordpress
cp -a wp-config-sample.php wp-config.php
vi wp-config.php
wp.config.php에서 위 mariadb에서 만들어준 DB와 계정 정보를 넣어줍니다.
/** The name of the database for WordPress */
define( ‘DB_NAME’, ‘wordpress’ );
/** MySQL database username */
define( ‘DB_USER’, ‘manvscloud’ );
/** MySQL database password */
define( ‘DB_PASSWORD’, ‘PW’ );
/** MySQL hostname */
define( ‘DB_HOST’, ‘127.0.0.1’ );
/** Database Charset to use in creating database tables. */
define( ‘DB_CHARSET’, ‘utf8’ );
/** The Database Collate type. Don’t change this if in doubt. */
define( ‘DB_COLLATE’, ” );
임시로 /home/php 사용자/그룹 권한을 apache로 한 뒤 Apache를 재시작합니다.
(테스트 후 사용자/그룹 권한을 변경하는 것을 권장합니다.)
chown -R apache:apache /home/php
apachectl rstart
[ 사이트 접속 해보기 ]


글쓰기 테스트 및 플러그인 설치/활성화까지 잘 되었습니다.
(플러그인 설치를 원활히 하려면 wp-config.php에 추가 옵션이 필요할 수 있습니다.)
PHP8에서 추가되거나 달라지는 부분은 추가 링크로 남기도록 하겠습니다.
https://www.php.net/releases/8.0/en.php
https://www.inflearn.com/course/php8-new-features#
PHP 8버전 컴파일은 성공적이었습니다.
마지막으로 PHP 8 컴파일 컨텐츠를 해볼 수 있도록 제안해주신 리눅서님에게
감사의 인사 올립니다. 많은 공부가 되었습니다.
https://linuxer.name/
긴 글 읽어주셔서 감사합니다.