部署

由于扩展需求不确定,编译安装需要同时编译扩展,采用第三方源包安装。

  1. yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
  2. yum install yum-utils

版本共存

7.1

  1. yum-config-manager --enable remi-php71
  2. yum update
  3. yum -y install php71
  4. 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

  1. yum-config-manager --enable remi-php74
  2. yum update
  3. yum -y install php74
  4. 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

  1. yum-config-manager --enable remi-php80
  2. yum update
  3. yum -y install php80
  4. 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 端口上侦听,所以更改默认端口即可实现多版本共存:

  1. sed -i 's/:9000/:9071/' /etc/opt/remi/php71/php-fpm.d/www.conf
  2. sed -i 's/:9000/:9074/' /etc/opt/remi/php74/php-fpm.d/www.conf
  3. 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

  1. touch /dev/shm/php74-fpm-cgi.sock
  2. chown www:www /dev/shm/php74-fpm-cgi.sock
  3. chmod 666 /dev/shm/php74-fpm-cgi.sock
  4. ls -al /dev/shm

依次修改,将 listen 参数修改为 /dev/shm/php74-fpm-cgi.sock:

  1. listen=/dev/shm/php74-fpm-cgi.sock
  2. #重启nginx和php-fpm服务(最好先重启php-fpm再重启nginx)
  3. systemctl restart php74-php-fpm & systemctl restart nginx
  4. netstat -anp | grep 9074

单个版本

安装指定版本 php,以 8.0 为例:

  1. yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
  2. yum install yum-utils
  3. yum-config-manager --enable remi-php80
  4. yum update
  5. 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

只要资源允许,可以无数版本共存,以下以PHP74为例:

启动相关

  1. #多版本
  2. systemctl enable php74-php-fpm
  3. systemctl start php74-php-fpm
  4. systemctl status php74-php-fpm
  5. systemctl stop php74-php-fpm
  6. #单版本
  7. systemctl enable php-fpm
  8. systemctl start php-fpm
  9. systemctl status php-fpm
  10. systemctl stop php-fpm

配置

php-fpm

多版本:vim /etc/opt/remi/php74/php-fpm.d/www.conf
单版本:vim /etc/php-fpm.d/www.conf

  1. listen = 127.0.0.1:9000
  2. listen.backlog = 1024
  3. #慢日志路径
  4. slowlog = /var/log/php-fpm/www-slow.log
  5. #开启慢日志
  6. request_slowlog_timeout = 5
  7. pm.max_children = 300
  8. pm.start_servers = 20
  9. pm.min_spare_servers = 5
  10. #动态方式下的最大 php-fpm 进程数量
  11. pm.max_spare_servers = 200
  12. #最大处理请求数
  13. pm.max_requests = 10240
  14. #单次请求最大执行时间
  15. request_terminate_timeout = 30
  16. #最大执行时间
  17. max_execution_time = 120

php

多版本:vim /etc/opt/remi/php74/php.ini
单版本:vim /etc/php.ini

  1. php --ini
  2. #修改 short_open_tag = Off
  3. short_open_tag = On

其他设置

Opcache.jit

vim /etc/php.d/10-opcache.ini

  1. opcache.jit = 1205
  2. opcache.jit_buffer_size = 64M
  3. #预加载
  4. opcache.file_cache = /tmp

Swoole 短标签

vim /etc/php.d/40-swoole.ini

  1. swoole.use_shortname = Off