OS

2022.02.16 15:15

CentOS 환경하에서 PHP 8 버전 컴파일 설치

  • 비아웹 오래 전 2022.02.16 15:15 인기
  • 5,281
    0

안녕하세요 비아웹입니다.

PHP 버전이 7.4 이후에 8버전이 출시되었습니다.

해당 8버전의 주요 기능으로는 JIT 컴파일과 유니온 형이 적용 되었습니다.

 

1. 주요 기능

JIT : ‘저스트인타임(just in time)’의 약자로 변환된 코드를 미리 저장해 비슷한 명령이 요구되면 해당 코드를 바로 사용해 속도를 높이는 기술

유니온형: 1개밖에 지정할 수 없는 'int'나 'string' 등의 변수 유형을 여러 개 지정할 수 있는 변수 타입

 

2. 테스트 환경

CentOS Linux release 7.6.1810 (Core)

Apache, php, mysql 을 모두 컴파일로 설치하는 구성으로 테스트 되었으며,

설치 순서는 apache 나 mysql 을 먼저 설치하고, php 를 마지막에 컴파일 진행합니다.

 

3. 의존성 패키지 설치

yum -y install gcc-c++ gcc autoconf bison libcurl-devel bzip2-devel gd-devel gmp-devel \
libicu-devel libxslt-devel zlib-devel libwebp-devel e2fsprogs-devel krb5-devel libidn-devel \
ncurses-devel gdbm-devel libxml2-devel freetype-devel libpng* libjpeg* gd-devel enchant-devel \
netpbm* libxslt* gmp-devel systemd-devel readline-devel sqlite-devel openldap-devel

yum 으로 설치되지 않는 추가 패키지 설치

rpm -Uvh http://www6.atomicorp.com/channels/atomic/centos/7/x86_64/RPMS/oniguruma-5.9.5-3.el7.art.x86_64.rpm rpm -Uvh http://www6.atomicorp.com/channels/atomic/centos/7/x86_64/RPMS/oniguruma-devel-5.9.5-3.el7.art.x86_64.rpm rpm -Uvh http://packages.psychotic.ninja/7/plus/x86_64/RPMS/libzip-0.11.2-6.el7.psychotic.x86_64.rpm rpm -Uvh http://packages.psychotic.ninja/7/plus/x86_64/RPMS/libzip-devel-0.11.2-6.el7.psychotic.x86_64.rpm

 

4. 소스 다운로드

이번 테스트는 php 8.0.3 으로 테스트 되었으며, 소스 위치는 아래와 같습니다.

https://www.php.net/distributions/php-8.0.3.tar.gz

 

5. 컴파일 옵션

./configure --prefix=/usr/local/php \ --with-apxs2=/usr/local/apache/bin/apxs \ --with-config-file-path=/usr/local/apache/conf \ --with-config-file-scan-dir=/usr/local/apache/conf \ --with-openssl \ --with-mysql-sock=/tmp/mysql.sock \ --with-mysqli \ --with-pdo-mysql \ --with-enchant \ --with-gettext \ --with-freetype \ --with-jpeg \ --with-webp \ --with-xpm \ --with-zlib \ --with-gmp \ --with-iconv \ --with-gdbm \ --with-bz2 \ --with-curl \ --with-mhash \ --with-xsl \ --with-readline \ --with-curl \ --with-pear \ --with-gettext \ --with-ldap \ --with-libxml \ --with-zip \ --with-libdir=lib64 \ --enable-gd \ --enable-litespeed \ --enable-mysqlnd \ --enable-bcmath \ --enable-sockets \ --enable-pcntl \ --enable-ftp \ --enable-bcmath \ --enable-mbstring \ --enable-calendar \ --enable-simplexml \ --enable-session \ --enable-soap \ --enable-xml \ --enable-opcache \ --enable-intl \ --enable-cli \ --enable-zts \ --enable-debug \ --enable-mbregex \ --enable-dba \ --enable-shmop \ --enable-sysvsem \ --enable-sysvshm \ --enable-sysvmsg \ --enable-exif \ --enable-fpm

상위의 컴파일 옵션은 fpm 과 모듈 방식 둘다 설치됩니다.

기존 7 버전 대비 컴파일 옵션이 변경된 내용

- 소스 폴더의 configure 파일에서 컴파일 옵션명 확인 가능합니다.

–enable-zip :with-zip 로 변경됨 –with-gd : –enable-gd 로 변경됨 –with-jpeg-dir /with-libxml-dir /with-png-dir /with-freetype-dir :-dir 삭제됨 –with-png : 옵션 삭제됨
make -j `grep processor /proc/cpuinfo | wc -l` make install

cpu 코어를 모두 활용해서 make 하는 옵션인 make -j 를 사용하였습니다.

 

6. 주요 오류

- 기존 설치된 패키지와의 의존성 관계 등으로 인하여 발생하는 오류 중 icu 관련 오류 발생시 조치 사항

checking for icu-uc >=50.1 icu-io icu-i18n... no configure: error: Package requirements(icu-uc >=50.1 icu-io icu-i18n) were not met: No package'icu-uc' found No package'icu-io' found No package'icu-i18n' found

조치 방법

wget https://github.com/unicode-org/icu/releases/download/release-65-1/icu4c-65_1-src.tgz tar -zxvpf icu4c-65_1-src.tgz cd icu/source ./configure --prefix=/usr make && make install export PKG_CONFIG_PATH=/usr/lib/pkgconfig

 

7. 설치 후 php.ini 내의 opcache 활성화

zend_extension=opcache [opcache] opcache.enable=1 opcache.enable_cli=1 opcache.memory_consumption=128 opcache.interned_strings_buffer=8 opcache.max_accelerated_files=50000 opcache.revalidate_freq=60 opcache.jit_buffer_size=100M opcache.jit=tracing

 

8. php-fpm 사용시 서비스 등록

a. httpd.conf 파일에서 proxy 모듈 활성화

LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so

b. 서비스 등록

컴파일 진행 한 폴더의 ./sapi/fpm/php-fpm.service파일을 /usr/lib/systemd/system/ 로 복사

systemctl daemon-reload / 서비스 자동 시작 등록 진행하시면 됩니다.

# cp ./sapi/fpm/php-fpm.service /usr/lib/systemd/system/ # systemctl daemon-reload # systemctl enable php-fpm

cf. 이상의 메뉴얼은 단순하게 php 8 컴파일 및 서비스 등록에 대해서만 진행되었으며,

php-fpm.conf 및 www.conf 에 대해서는 아래에 단순 예제 파일만 남기도록 하겠습니다.

php-fpm.conf

[global] pid =/var/run/php-fpm.pid error_log =/var/log/php-fpm.log daemonize = yes include=/usr/local/php/etc/php-fpm.d/*.conf

www.conf

[www] user = nobody group = nobody listen =/var/run/php-fpm.sock ;listen =127.0.0.1:9000 listen.owner = nobody listen.group = nobody pm = dynamic pm.max_children =50 pm.start_servers =5 pm.min_spare_servers =5 pm.max_spare_servers =10

감사합니다.

서버호스팅 비아웹

  • 공유링크 복사