Linux CentOS安装PHP多版本同时运行

Linux CentOS安装PHP多版本同时运行,第1张

mkdir -p /lnmp/php74

wget https://www.php.net/distributions/php-7.4.33.tar.gz

tar -zxvf php-7.4.33

cd ./php-7.4.33

./configure --prefix=/lnmp/php74 --enable-fpm --with-mysqli --with-curl --with-pdo_mysql --with-pdo_sqlite --enable-mysqlnd --enable-mbstring --with-gd --with-freetype

(7.4之前的版本freetype是 --with-freetype-dir )

make

make install

cp php.ini-development /lnmp/php74/lib/php.ini

cd /lnmp/php74/etc

mv php-fpm.conf.default php-fpm.conf

mv php-fpm.d/www.conf.default php-fpm.d/www.conf

cd /lnmp/php71/etc/php-fpm.d

vim www.conf

cgi.fix_pathinfo=0

/lnmp/php71/sbin/php-fpm

ps aux|grep php

vim /etc/init.d/php71-fpm

chmod a+x /etc/init.d/php71-fpm

chkconfig --add php71-fpm

service php71-fpm start

service php71-fpm restar

service php71-fpm stop

把不同版本的php在不同端口运行比较好,比如80运行5.6, 85运行5.4。服务器开2个进程。

同一个端口运行两个版本不好区分,以前用文件名区分比如.php5,.php7但只适合自己的代码,运行外来代码还是很不方面

Linux下部署php多版本共存

背景说明

自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源码包。

通过源码安装

# 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 配置

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 配置

------------------------------

# vim /usr/local/php/etc/php-fpm.conf1

[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

# 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

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 开机自动启动

# chkconfig --add php54-fpm

# chkconfig php54-fpm on


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/8396925.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-16
下一篇 2023-04-16

发表评论

登录后才能评论

评论列表(0条)

保存