linux nginx 多个php版本,linux下nginx多版本php共存

应用环境php

LNMP的环境,当前PHP版本5.3.8,遇到一个应用需求只支持PHP 5.2.x,又但愿保持现有应用仍是用PHP 5.3.8。也就是说须要两个版本的PHP同时存在,供nginx根据须要调用不一样版本。html

思路mysql

Nginx是经过PHP-FastCGI与PHP交互的。而PHP-FastCGI运行后会经过文件、或本地端口两种方式进行监听,在Nginx中配置相应的FastCGI监听端口或文件即实现Nginx请求对PHP的解释。linux

既然PHP-FastCGI是监听端口和文件的,那就可让不一样版本的PHP-FastCGI同时运行,监听不一样的端口或文件,Nginx中根据需求配置调用不一样的PHP-FastCGI端口或文件,便可实现不一样版本PHP共存了。nginx

配置记录sql

下面记录简单的配置流程,基于已经安装了lnmp的debian环境。当前版本的PHP是5.3.8,位于/usr/local/php。api

1.下载PHP-5.2.14及相关的FPM、autoconf组件:服务器

帮助dom

1curl

2

3

4

mkdir ~/php5.2

cd ~/php5.2

wget -c http://museum.php.net/php5/php-5.2.14.tar.gz

wget -c http://php-fpm.org/downloads/php-5.2.14-fpm-0.5.14.diff.gz

2.解压PHP-5.2.14,并打上PHP-FPM的补丁:

帮助

1

2

tar zxvf php-5.2.14.tar.gz

gzip -cd php-5.2.14-fpm-0.5.14.diff.gz | patch -d php-5.2.14 -p1

3.若是你已经经过lnmp安装,应该已经安装好了autoconf,若是没有,请自行下载并编译autoconf-2.13,而后设置autoconf环境变量:

帮助

1

2

export PHP_AUTOCONF=/usr/local/autoconf-2.13/bin/autoconf¬

export PHP_AUTOHEADER=/usr/local/autoconf-2.13/bin/autoheader

3.编译安装PHP-5.2.14在新的路径(/usr/local/php-5.2.14)下,注意–prefix、–with-config-file-path的路径,而且打开fastcgi和fpm选项:

帮助

1

2

3

4

5

cd php-5.2.14/

./buildconf --force

./configure --prefix=/usr/local/php-5.2.14 --with-config-file-path=/usr/local/php-5.2.14/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-fastcgi --enable-fpm

make ZEND_EXTRA_LIBS='-liconv'

make install

4.设置/usr/local/php-5.2.14/etc/php-fpm.conf,监听端口:

帮助

1

127.0.0.1:9001

或者监听文件:

帮助

1

/path/to/unix/socket

其余参数根据服务器环境和需求自行定制。

5.启动php-fpm,之后能够经过php-fpm进行管理:

帮助

1

/usr/local/php-5.2.14/sbin/php-fpm start

字php5.3.3后,php已经将php-fpm继承到php中,并且内置的php-fpm默认不支持(start|stop|reload)的平滑启动参数,须要使用官方源代码中提供的启动脚原本控制:

帮助

1

2

3

cp -f (php -5.3.x-source-dir)/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

chmod 755 /etc/init.d/php-fpm

/etc/init.d/php-fpm start

php-fpm支持的操做:

start,启动PHP的FastCGI进程。

stop,强制终止PHP的FastCGI进程。

quit,平滑终止PHP的FastCGI进程。

restart, 重启PHP的FastCGI进程。

reload, 从新加载PHP的php.ini。

logrotate, 从新启用log文件。

5.3.3的php-fpm脚本支持的操做:start|stop|force-quit|restart|reload|status

6.配置好PHP-5.2.14的php.ini,从新加载生效:

帮助

1

2

vi /usr/local/php-5.2.14/etc/php.ini

/usr/local/php-5.2.14/sbin/php-fpm reload

7.修改nginx配置,对须要的服务配置使用PHP-5.2.14:

帮助

1

2

3

4

5

6

location ~ .*.(php|php5)?$

{

fastcgi_pass  127.0.0.1:9001;

fastcgi_index index.php;

include fcgi.conf;

}

8.记录一下本身编译php5.5.10使用的配置

帮助

1

./configure --prefix=/usr/local/php-5.5.10 --with-config-file-path=/usr/local/php-5.5.10/etc --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-bz2 --with-curl=/usr/bin --enable-ftp --enable-sockets --disable-ipv6 --with-gd --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --with-freetype-dir=/usr/local --enable-gd-native-ttf --with-iconv-dir=/usr/local --enable-mbstring --enable-calendar --with-gettext --with-libxml-dir=/usr/local --with-zlib --with-pdo-mysql=mysqlnd --enable-dom --enable-xml --enable-fpm --with-libdir=lib64 --with-mcrypt=/usr/bin --enable-zip --enable-soap --enable-mbstring  --with-gd --with-openssl --enable-pcntl --with-xmlrpc --enable-opcache

参考资料:

http://ixdba.blog.51cto.com/2895551/806622

http://www.yinfor.com/blog/archives/2008/05/install_zend_optimizer_33_on_c.html

http://ideas.spkcn.com/technology/php-technology/133.html

http://zhangxugg-163-com.iteye.com/blog/1894990

Posted in linux, php | 1 Response

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值