自php7問世,身為最新版本控的我馬上升級體驗(yàn),但是由于服務(wù)器上還有舊程序在運(yùn)行,只好部署一個php多版本共存環(huán)境。
現(xiàn)有環(huán)境是lnmp
- CentOS 6.7
- nginx 1.10.1
- mariadb-10.0.26
- php 7.0.8
為了更好兼容舊的php程序,推薦使用5.4.45. 主要是兼容mysql擴(kuò)展。
開始安裝
首先要下載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.conf
[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
注意:重點(diǎn)是配置監(jiān)聽端口和進(jìn)程
啟動 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配置,對需要的服務(wù)配置使用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 開機(jī)自動啟動
# chkconfig --add php54-fpm
# chkconfig php54-fpm on
chkconfig 功能說明:檢查,設(shè)置系統(tǒng)的各種服務(wù)。
語法:chkconfig [–add][–del][–list][系統(tǒng)服務(wù)]
chkconfig [–level <等級代號>][系統(tǒng)服務(wù)][on/off/reset]
本方案的重點(diǎn)是
每個PHP版本都要安裝在新的獨(dú)立的文件夾里
每個PHP版本的php-fpm.conf配置文件都需要設(shè)置不同的進(jìn)程名和監(jiān)聽端口
nginx配置文件中指定要使用的PHP版本監(jiān)聽端口或進(jìn)程名