PHP 8.0 is a major update of the PHP language released at Nov 26, 2020. It contains many new features and optimizations including named arguments, union types, attributes, constructor property promotion, match expression, nullsafe operator, JIT, and improvements in the type system, error handling, and consistency.
Check out the more futures here PHP: PHP8.0 Release
Contents
Releated Articles
- [LNMP] Centos8 compile and install Nginx
- [LNMP] Centos8 install MySQL
- [LNMP] Centos8 compile and install Redis and phpredis extension
Update System
Update your system packages to the newest
yum update
Download PHP Source File
You could download source file at PHP:Downloads
wget https://www.php.net/distributions/php-8.0.0.tar.gz
tar -xvzf php-8.0.0.tar.gz
cd php-8.0.0
Install Compiler Kit
Install compiler kit make
gcc
and g++
yum install gcc gcc-c++ make
Install dependencies
yum install libxml2 libxml2-devel openssl openssl-devel freetype freetype-devel libzip libzip-devel sqlite sqlite-devel gd gd-devel libcurl-devel libicu libicu-devel libxslt libxslt-devel
How to install oniguruma refers to the articles before Fix php7.4 no package ‘oniguruma’ found
yum install https://rpms.remirepo.net/enterprise/8/remi/x86_64/oniguruma5php-6.9.6-1.el8.remi.x86_64.rpm
yum install https://rpms.remirepo.net/enterprise/8/remi/x86_64/oniguruma5php-devel-6.9.6-1.el8.remi.x86_64.rpm
Compile
Run configure
command to generize makefile
./configure \
--prefix=/usr/local/php \
--with-zlib-dir \
--enable-mbstring \
--enable-soap \
--enable-calendar \
--with-curl \
--disable-rpath \
--enable-gd \
--enable-gd-jis-conv \
--with-bz2 \
--with-zlib \
--enable-sockets \
--enable-sysvsem \
--enable-sysvshm \
--enable-pcntl \
--enable-mbregex \
--enable-exif \
--enable-bcmath \
--with-mhash \
--with-pdo-mysql \
--with-mysqli \
--with-openssl \
--with-fpm-user=www \
--with-fpm-group=www \
--with-libdir=/lib/x86_64-linux-gnu/ \
--enable-ftp \
--with-gettext \
--with-xsl \
--enable-opcache \
--enable-fpm \
--with-iconv \
--with-zip \
--with-pear \
--with-freetype \
--enable-intl
Run make
commmand to compile
make -j4
-j4
stands for parallel compilation. It’s recommend to set to your CPU core number
Run make
command to install
make install
cp php.ini-production /usr/local/php/lib/php.ini
Configure PHP
Install path of PHP is under /usr/local/php
Create www user
useradd www
Modify php-fpm.conf
cd /usr/local/php/etc
cp php-fpm.conf.default php-fpm.conf
cd php-fpm.d
cp www.conf.default www.conf
Edit www.conf to configure the number of process according to the server performance and your service requirements
pm.max_children = 10
pm.start_servers = 5
pm.min_spare_servers = 4
pm.max_spare_servers = 7
Remove the first semicolon
;env[HOSTNAME] = $HOSTNAME
;env[PATH] = /usr/local/bin:/usr/bin:/bin
;env[TMP] = /tmp
;env[TMPDIR] = /tmp
;env[TEMP] = /tmp
Modify php.ini
cd /usr/local/php/lib
vim php.ini
Edit the memory limit
memory_limit = 512M
Edit the post size limit and the file upload limit
post_max_size = 512M
upload_max_filesize = 512M
Enable OPcache and JIT
Remove the first semicolon
;zend_extension=opcache
[opcache]
;opcache.enable=1
;opcache.memory_consumption=128
;opcache.interned_strings_buffer=8
;opcache.max_accelerated_files=10000
;opcache.validate_timestamps=1
Insert
opcache.jit_buffer_size=128
Register php-fpm as a system service
vim /usr/lib/systemd/system/php-fpm.service
Type
[Unit]
Description=The PHP FastCGI Process Manager
After=network.target
[Service]
Type=simple
PIDFile=/usr/local/php/var/run/php-fpm.pid
ExecStart=/usr/local/php/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
Set to run php-fpm at startup
systemctl enable php-fpm
systemctl start php-fpm
Show service status
systemctl status php-fpm