今天是php8.0.0正式版發布的第一天,
php8也是第一次引入jit特性,
php8正式版在生產環境應該如何安裝?
jit特性應該如何開啟?本文供大家參考
一,下載並解壓php8.0.0正式版的安裝包:
1,下載
[root@kubemaster source]# wget https://www.php.net/distributions/php-8.0.0.tar.gz
2,解壓
[root@kubemaster source]# tar -zxvf php-8.0.0.tar.gz
說明:劉宏締的架構森林是一個專注架構的博客,地址:https://www.cnblogs.com/architectforest
對應的源碼可以訪問這里獲取: https://github.com/liuhongdi/
說明:作者:劉宏締 郵箱: 371125307@qq.com
二,配置、編譯、安裝 php8:
1,查看配置的幫助:
[root@kubemaster php-8.0.0]# ./configure --help
php配置時參數時有變化,
不確定時可以查看這里給出的提示
2,配置
[root@kubemaster php-8.0.0]# ./configure --prefix=/usr/local/soft/php8 --with-config-file-path=/usr/local/soft/php8/etc
--with-curl --with-freetype --enable-gd --with-jpeg --with-gettext --with-kerberos --with-libdir=lib64 --with-libxml
--with-mysqli --with-openssl --with-pdo-mysql --with-pdo-sqlite --with-pear --enable-sockets --with-mhash --with-ldap-sasl
--with-xsl --with-zlib --with-zip -with-bz2 --with-iconv --enable-fpm --enable-pdo --enable-bcmath --enable-mbregex
--enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem
--enable-xml --enable-sysvsem --enable-cli --enable-opcache --enable-intl --enable-calendar --enable-static --enable-mysqlnd
配置成功后的提示:
+--------------------------------------------------------------------+ | License: | | This software is subject to the PHP License, available in this | | distribution in the file LICENSE. By continuing this installation | | process, you are bound by the terms of this license agreement. | | If you do not agree with the terms of this license, you must abort | | the installation process at this point. | +--------------------------------------------------------------------+ Thank you for using PHP.
3,編譯:
[root@kubemaster php-8.0.0]# make
make完成后的提示:
Build complete. Don't forget to run 'make test'.
4,安裝:
[root@kubemaster php-8.0.0]# make install
三,配置過程中的報錯和解決辦法
1,
configure: error: Package requirements (libxml-2.0 >= 2.9.0) were not met: Package 'libxml-2.0', required by 'virtual:world', not found
解決:
[root@kubemaster php-8.0.0]# dnf install libxml2-devel
2,
configure: error: Package requirements (sqlite3 > 3.7.4) were not met: Package 'sqlite3', required by 'virtual:world', not found
解決:
[root@kubemaster php-8.0.0]# dnf install sqlite-devel
3,
checking for BZip2 in default path... not found configure: error: Please reinstall the BZip2 distribution
解決:
[root@kubemaster php-8.0.0]# dnf -y install bzip2-devel
4,
configure: error: Package requirements (libcurl >= 7.29.0) were not met: Package 'libcurl', required by 'virtual:world', not found
解決:
[root@kubemaster php-8.0.0]# dnf -y install libcurl-devel
5,
configure: error: Package requirements (libpng) were not met: Package 'libpng', required by 'virtual:world', not found
解決:
[root@kubemaster php-8.0.0]# dnf -y install libpng-devel
6,
configure: error: Package requirements (libjpeg) were not met: Package 'libjpeg', required by 'virtual:world', not found
解決:
[root@kubemaster php-8.0.0]# dnf -y install libjpeg-devel
7,
configure: error: Package requirements (freetype2) were not met: Package 'freetype2', required by 'virtual:world', not found
解決:
[root@kubemaster php-8.0.0]# dnf -y install freetype-devel
8,
configure: error: Package requirements (icu-uc >= 50.1 icu-io icu-i18n) were not met: Package 'icu-uc', required by 'virtual:world', not found Package 'icu-io', required by 'virtual:world', not found Package 'icu-i18n', required by 'virtual:world', not found
解決:
[root@kubemaster php-8.0.0]# dnf -y install libicu-devel
9,
configure: error: Package requirements (oniguruma) were not met: Package 'oniguruma', required by 'virtual:world', not found
解決:
[root@kubemaster php-8.0.0]# dnf --enablerepo=PowerTools install oniguruma-devel
10,
configure: error: Package requirements (libxslt >= 1.1.0) were not met: Package 'libxslt', required by 'virtual:world', not found
解決:
[root@kubemaster php-8.0.0]# dnf -y install libxslt-devel
11,
configure: error: Package requirements (libzip >= 0.11 libzip != 1.3.1 libzip != 1.7.0) were not met: Package 'libzip', required by 'virtual:world', not found
解決:
[root@kubemaster php-8.0.0]# dnf -y install libzip-devel
四,測試php8安裝是否成功:
[root@kubemaster php-8.0.0]# /usr/local/soft/php8/bin/php --version PHP 8.0.0 (cli) (built: Nov 27 2020 14:34:26) ( NTS ) Copyright (c) The PHP Group Zend Engine v4.0.0-dev, Copyright (c) Zend Technologies
五,生成各個配置文件:
1,生成php.ini配置文件:
[root@kubemaster php-8.0.0]# cp php.ini-production /usr/local/soft/php8/etc/php.ini
2,生成www.conf配置文件
[root@kubemaster php-8.0.0]# cd /usr/local/soft/php8/etc/php-fpm.d/ [root@kubemaster php-fpm.d]# cp www.conf.default www.conf
3,生成php-fpm的配置文件
[root@kubemaster php-fpm.d]# cd /usr/local/soft/php8/etc/ [root@kubemaster etc]# cp php-fpm.conf.default php-fpm.conf
六,啟動php-fpm
1,生成php-fpm啟動文件
[root@kubemaster ~]# mkdir /usr/local/soft/php8/daemon [root@kubemaster ~]# cp /usr/local/source/php-8.0.0/sapi/fpm/init.d.php-fpm /usr/local/soft/php8/daemon/php-fpm [root@kubemaster ~]# chmod 740 /usr/local/soft/php8/daemon/php-fpm
2,啟動php-fpm
[root@kubemaster ~]# /usr/local/soft/php8/daemon/php-fpm start Starting php-fpm done
3, 查看進程中是否已啟動
[root@kubemaster ~]# ps auxfww | grep php | grep -v grep root 218090 0.0 0.2 190036 9092 ? Ss 14:49 0:00 \_ php-fpm: master process (/usr/local/soft/php8/etc/php-fpm.conf) nobody 218091 0.0 0.2 214168 9664 ? S 14:49 0:00 \_ php-fpm: pool www nobody 218092 0.0 0.2 214168 9664 ? S 14:49 0:00 \_ php-fpm: pool www
4,查看php-fpm默認守護的端口:
[root@kubemaster html]# ss -lntp | grep php LISTEN 0 128 127.0.0.1:9000 0.0.0.0:* users:(("php-fpm",pid=218092,fd=5),("php-fpm",pid=218091,fd=5),("php-fpm",pid=218090,fd=10))
可以看到是9000
七,配置nginx訪問php-fpm
1,准備測試用的目錄和代碼:
[root@kubemaster web]# mkdir /data/web/phpweb [root@kubemaster web]# mkdir /data/web/phpweb/html [root@kubemaster web]# cd /data/web/phpweb/html [root@kubemaster html]# vi info.php [root@kubemaster html]# more info.php <?php phpinfo(); ?>
2,配置nginx
在nginx的配置文件中增加一個虛擬主機,使可以訪問php
demo如下:
server { listen 8003; root /data/web/phpweb/html; location ~ \.php { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
然后重啟nginx
3,從瀏覽器訪問php
訪問:
http://127.0.0.1:8003/info.php
瀏覽器返回
可見php8已安裝成功
九,啟用php8的jit特性:
1,編輯php.ini
;啟用opcache
opcache.enable=1 opcache.enable_cli=1
;啟用jit,並指定jit的buffer
opcache.jit_buffer_size=128M opcache.jit=1255
;zend對opcache模塊的引用,要打開
zend_extension=opcache
說明:關於如何設置jit的配置值,可以參考鳥哥的這個文檔:
https://www.laruence.com/2020/06/27/5963.html
2,重啟php-fpm的daemon:
[root@kubemaster html]# /usr/local/soft/php8/daemon/php-fpm stop Gracefully shutting down php-fpm . done [root@kubemaster html]# /usr/local/soft/php8/daemon/php-fpm start Starting php-fpm done
3,查看phpinfo的變化:
需要能看到zend opcache一項,
否則opcache未生效
注意看JIT中的一項,需要值為On
opcache.jit的值也是我們所設置的值

4,用php代碼測試jit的狀態?
[root@kubemaster html]# more jit.php <?php var_dump(opcache_get_status()['jit']); ?>
訪問:
http://127.0.0.1:8003/jit.php
返回:
array(7) { ["enabled"]=> bool(true) ["on"]=> bool(true) ["kind"]=> int(5) ["opt_level"]=> int(5) ["opt_flags"]=> int(6) ["buffer_size"]=> int(104857584) ["buffer_free"]=> int(104855312) }
注意:如果enabled和on兩項的值都為true,
則表示jit已開啟
十,查看linux的版本:
[root@kubemaster html]# cat /etc/redhat-release CentOS Linux release 8.2.2004 (Core)