当前服务器用的是军哥lnmp1.3一键包,已经装好了php5.6,在此基础上,并存一个php5.4的版本。
废话不多说直接进入主题!
编译安装php-5.4.45
下载php5.4.45源码包
cd /usr/src
wget http://cn.php.net/distributions/php-5.4.45.tar.gz
解压缩源码包
tar zxf php-5.4.45.tar.gz
进入php-5.4.45目录进行编译(注意./configure里指定的路径,当前php-5.6用的/usr/local/php路径,所以我这里就把路径改成了/usr/local/php54路径,避免和php-5.6版本冲突)
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
复制一个php.ini文件
cp php.ini-production /usr/local/php54/etc/php.ini
复制php-fpm启动
cp sapi/fpm/init.d.php-fpm /etc/init.d/php54-fpm
chmod +x /etc/init.d/php54-fpm
编辑php.ini文件,修改几项参数
post_max_size = 50M
upload_max_filesize = 32M
date.timezone = PRC
short_open_tag = On
cgi.fix_pathinfo=0
max_execution_time = 300
修改php-fpm.conf
cd /usr/local/php54/etc/
cp php-fpm.conf.default php-fpm.conf
vim php-fpm.conf
直接将原有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 = 80
pm.start_servers = 40
pm.min_spare_servers = 40
pm.max_spare_servers = 80
request_terminate_timeout = 100
request_slowlog_timeout = 0
slowlog = var/log/slow.log
启动php54-fpm
/etc/init.d/php54-fpm start
修改nginx配置,配置php
location ~ 1.php(/|$)
{
try_files $uri =404;
fastcgi_pass unix:/tmp/php54-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
服务器上编辑个phpinfo.php
<?php
phpinfo()
?>
访问一下看看,当当当php5.4.45出现了,表示php多版本共存安装成功。
再将fastcgi_pass unix:/tmp/php54-cgi.sock;改成fastcgi_pass unix:/tmp/php-cgi.sock;又可以看到php5.6了.
PS:php.ini和php-fpm我这里只是给个示例,实际使用中,根据情况自行调整。
- / ↩