CentOS 7 环境 PHP8.0 编译安装以及开启 JIT
PHP是超文本预处理器(Hypertext Preprocessor)的简称,是一种用于创建动态性交互网站的强有力的语言。
安装相关依赖
yum install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses curl gdbm-devel db4-devel libXpm-devel libX11-devel gd-devel gmp-devel expat-devel xmlrpc-c xmlrpc-c-devel libicu-devel libmcrypt-devel libmemcached-devel
下载并解压
wget https://www.php.net/distributions/php-8.0.0.tar.gz
tar -zxvf php-8.0.0.tar.gz
生成预编译文件 Makefile
cd php-8.0.0
# 生成 Makefile
./configure \
--prefix=/usr/local/php8 \
--with-config-file-path=/usr/local/php8/etc \
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
--with-curl \
--with-freetype-dir \
--enable-gd \
--with-gettext \
--with-iconv-dir \
--with-kerberos \
--with-libdir=lib64 \
--with-libxml-dir \
--with-mysqli \
--with-openssl \
--with-pcre-regex \
--with-pdo-mysql \
--with-pdo-sqlite \
--with-pear \
--with-png-dir \
--with-jpeg-dir \
--with-xmlrpc \
--with-xsl \
--with-zlib \
--with-bz2 \
--with-mhash \
--enable-bcmath \
--enable-libxml \
--enable-inline-optimization \
--enable-mbregex \
--enable-mbstring \
--enable-opcache \
--enable-pcntl \
--enable-shmop \
--enable-soap \
--enable-sockets \
--enable-sysvsem \
--enable-sysvshm \
--enable-xml \
--enable-zip
如果看到以下提示信息,说明 configure 这步已经成功啦。
可能会出现错误
- configure: error: Package requirements (sqlite3 > 3.7.4) were not met: No package ‘sqlite3’ found
解决方法:yum install libsqlite3x-devel -y
- configure: error: Package requirements (oniguruma) were not met
解决方法:yum install oniguruma-devel -y
- configure: error: Package requirements (libxml-2.0 >= 2.7.6) were not met:
No package ‘libxml-2.0’ found
解决方法:yum install libxml2-devel.x86_64
- configure: error: Package requirements (sqlite3 > 3.7.4) were not met:
No package ‘sqlite3’ found
解决方法:yum install sqlite-devel.x86_64
编译安装
make && make install
安装成功执行 /usr/local/php8/bin/php -v
[root@i14kuk3fpixkevvZ vhost]# /usr/local/php8/bin/php -v
PHP 8.0.0 (cli) (built: Jan 5 2021 06:38:02) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.0-dev, Copyright (c) Zend Technologies
with Zend OPcache v8.0.0, Copyright (c), by Zend Technologies
配置文件
- 复制 php 配置文件
- 复制 php-fpm 配置文件
- 修改 php-fpm 配置
cp php.ini-production /usr/local/php8/etc/php.ini
cp /usr/local/php8/etc/php-fpm.conf.default /usr/local/php8/etc/php-fpm.conf
cp /usr/local/php8/etc/php-fpm.d/www.conf.default /usr/local/php8/etc/php-fpm.d/www.conf
php-fpm.conf 中开启 pid = run/php-fpm.pid 配置项
配置启动 php-fpm
复制 php-fpm 的启动脚本 cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
增加执行权限 chmod +x /etc/init.d/php-fpm
启动 php-fpm/etc/init.d/php-fpm start
或者 service php-fpm start
开启 opcache 和 JIT
opcache
配置参数参考:https://www.php.net/manual/zh/opcache.configuration.phpJIT
配置参数参考:https://www.laruence.com/2020/06/27/5963.html
添加配置到 /usr/local/php8/etc/php.ini
启用并配置 opcache
zend_extension
的路径替换为你自己的路径
zend_extension=/usr/local/php8/lib/php/extensions/no-debug-non-zts-20200930/opcache.so
[opcache]
opcache.enable=1
opcache.enable_cli=1
opcache.memory_consumption=192
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
配置 JIT
opcache.jit=1205
opcache.jit_buffer_size=64M
重新启动 php-fpm
service php-fpm restart
配置 nginx
新建 index.php
在 /usr/local/nginx/html
目录下创建 index.php
<?php
phpinfo();
?>
修改nginx配置
server {
listen 8082;
server_name 127.0.0.1;
root /usr/local/nginx/html;
index index.html index.htm index.php;
charset utf-8;
location ~ \.php$ {
fastcgi_connect_timeout 30;
fastcgi_send_timeout 30;
fastcgi_read_timeout 30;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
}
测试php环境
浏览器访问 127.0.0.1:8082
返回结果:
Zend OPcache
php.ini 中 JIT 配置信息
增加全局 php 环境变量
vim /etc/profile
,添加配置到最后:
PATH=$PATH:/usr/local/php8/bin
export PATH
source /etc/profile
其他参考