部署
由于扩展需求不确定,编译安装需要同时编译扩展,采用第三方源包安装。
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum install yum-utils
版本共存
7.1
yum-config-manager --enable remi-php71
yum update
yum -y install php71
yum -y install php71-php-fpm php71-php-gd php71-php-zip php71-php-json php71-php-mbstring php71-php-mysqlnd php71-php-xml php71-php-xmlrpc php71-php-opcache php71-php-swoole php71-php-redis
7.4
yum-config-manager --enable remi-php74
yum update
yum -y install php74
yum -y install php74-php-fpm php74-php-gd php74-php-zip php74-php-json php74-php-mbstring php74-php-mysqlnd php74-php-xml php74-php-xmlrpc php74-php-opcache php74-php-swoole php74-php-redis
8.0
yum-config-manager --enable remi-php80
yum update
yum -y install php80
yum -y install php80-php-fpm php80-php-gd php80-php-zip php80-php-json php80-php-mbstring php80-php-mysqlnd php80-php-xml php80-php-xmlrpc php80-php-opcache php80-php-swoole php80-php-redis
共存配置
采用 TCP 端口监听
每个 php-fpm 版本都在 9000 端口上侦听,所以更改默认端口即可实现多版本共存:
sed -i 's/:9000/:9071/' /etc/opt/remi/php71/php-fpm.d/www.conf
sed -i 's/:9000/:9074/' /etc/opt/remi/php74/php-fpm.d/www.conf
sed -i 's/:9000/:9080/' /etc/opt/remi/php80/php-fpm.d/www.conf
使用 UNIX Domain Socket
https://linuxeye.com/364.html
https://www.php.cn/php-weizijiaocheng-440257.html
touch /dev/shm/php74-fpm-cgi.sock
chown www:www /dev/shm/php74-fpm-cgi.sock
chmod 666 /dev/shm/php74-fpm-cgi.sock
ls -al /dev/shm
依次修改,将 listen 参数修改为 /dev/shm/php74-fpm-cgi.sock:
listen=/dev/shm/php74-fpm-cgi.sock
#重启nginx和php-fpm服务(最好先重启php-fpm再重启nginx)
systemctl restart php74-php-fpm & systemctl restart nginx
netstat -anp | grep 9074
单个版本
安装指定版本 php,以 8.0 为例:
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum install yum-utils
yum-config-manager --enable remi-php80
yum update
yum -y install php php-fpm php-gd php-zip php-json php-mbstring php-mysqlnd php-xml php-xmlrpc php-opcache php-redis php-bcmath php-swoole
启动相关
#多版本
systemctl enable php74-php-fpm
systemctl start php74-php-fpm
systemctl status php74-php-fpm
systemctl stop php74-php-fpm
#单版本
systemctl enable php-fpm
systemctl start php-fpm
systemctl status php-fpm
systemctl stop php-fpm
配置
php-fpm
多版本:vim /etc/opt/remi/php74/php-fpm.d/www.conf
单版本:vim /etc/php-fpm.d/www.conf
listen = 127.0.0.1:9000
listen.backlog = 1024
#慢日志路径
slowlog = /var/log/php-fpm/www-slow.log
#开启慢日志
request_slowlog_timeout = 5
pm.max_children = 300
pm.start_servers = 20
pm.min_spare_servers = 5
#动态方式下的最大 php-fpm 进程数量
pm.max_spare_servers = 200
#最大处理请求数
pm.max_requests = 10240
#单次请求最大执行时间
request_terminate_timeout = 30
#最大执行时间
max_execution_time = 120
php
多版本:vim /etc/opt/remi/php74/php.ini
单版本:vim /etc/php.ini
php --ini
#修改 short_open_tag = Off
short_open_tag = On
其他设置
Opcache.jit
vim /etc/php.d/10-opcache.ini
opcache.jit = 1205
opcache.jit_buffer_size = 64M
#预加载
opcache.file_cache = /tmp
Swoole 短标签
vim /etc/php.d/40-swoole.ini
swoole.use_shortname = Off