Linux系统下多版本php共存的解决方案(超简单)

吾爱主题 阅读:126 2024-04-05 13:55:24 评论:0

自php7问世,身为最新版本控的我马上升级体验,但是由于服务器上还有旧程序在运行,只好部署一个php多版本共存环境。

现有环境是lnmp
- CentOS 6.7
- nginx 1.10.1
- mariadb-10.0.26
- php 7.0.8

为了更好兼容旧的php程序,推荐使用5.4.45. 主要是兼容mysql扩展。

开始安装

首先要下载php-5.4.45.tar.gz源码包。

通过源码安装

 

?
1 2 3 4 5 6 7 8 # tar xzvf php-5.4.45.tar.gz # cd php-5.4.45   # ./configure --prefix=/usr/local/php54 --with-config-file-path=/usr/local/php54/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir=/usr/local/freetype --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-gettext --disable-fileinfo --enable-intl --with-xsl   # make ZEND_EXTRA_LIBS='-liconv' # make install # cp php.ini-production /usr/local/php/etc/php.ini

php.ini 配置

 

?
1 2 3 4 5 6 7 post_max_size = 50M upload_max_filesize = 50M date .timezone = PRC short_open_tag = On cgi.fix_pathinfo=0 max_execution_time = 300 disable_functions=passthru, exec ,system,chroot,scandir, chgrp , chown ,shell_exec,proc_open,proc_get_status,popen,ini_alter,ini_restore,dl,openlog,syslog,readlink, symlink ,popepassthru,stream_socket_server

php-fpm.conf 配置

?
1 # vim /usr/local/php/etc/php-fpm.conf
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 [global] pid = /usr/local/php54/var/run/php-fpm .pid error_log = /usr/local/php54/var/log/php-fpm .log log_level = notice   [www] listen = /tmp/php54-cgi .sock listen.backlog = -1 listen.allowed_clients = 127.0.0.1:9001 listen.owner = www listen.group = www listen.mode = 0666 user = www group = www pm = dynamic pm.max_children = 40 pm.start_servers = 20 pm.min_spare_servers = 20 pm.max_spare_servers = 40 request_terminate_timeout = 100 request_slowlog_timeout = 0 slowlog = var /log/slow .log

注意:重点是配置监听端口和进程

启动 php-fpm

?
1 2 3 # cp sapi/fpm/init.d.php-fpm /etc/init.d/php54-fpm # chmod +x /etc/init.d/php54-fpm # /etc/init.d/php54-fpm start

修改nginx配置,对需要的服务配置使用php-5.4.45

?
1 2 3 4 5 6 7 location ~ [^/]\.php(/|$)   {    try_files $uri =404;    fastcgi_pass unix: /tmp/php54-cgi .sock;    fastcgi_index index.php;    include fastcgi.conf;   }

配置php-5.4.45 的php54-fpm 开机自动启动

?
1 2 # chkconfig --add php54-fpm # chkconfig php54-fpm on

chkconfig 功能说明:检查,设置系统的各种服务。
语法:chkconfig [–add][–del][–list][系统服务]
chkconfig [–level <等级代号>][系统服务][on/off/reset]

本方案的重点是

每个PHP版本都要安装在新的独立的文件夹里

每个PHP版本的php-fpm.conf配置文件都需要设置不同的进程名和监听端口

nginx配置文件中指定要使用的PHP版本监听端口或进程名

原文链接:https://blog.csdn.net/gxdvip/article/details/51787476

可以去百度分享获取分享代码输入这里。
声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

【腾讯云】云服务器产品特惠热卖中
搜索
标签列表
    关注我们

    了解等多精彩内容