Debian 下轻松实现 PHP 多版本共存

综合分类评论7,1681字数 383阅读模式

PHP7 的发布废弃了部分特性,一些程序或者插件当前不能很好的运行在 PHP7 上,因此如果服务器上能同时运行多个 PHP 的版本,就可以很好的解决过渡期的兼容性问题。在前面两篇文章中,我们介绍了如何在 Debian Stretch 中安装使用 PHP5,以及如何在Debian环境安装配置PHP 7.2。看完这两篇文章,细心的同学就会发现,两个版本的PHP共存,是很好实现的。

Debian 下轻松实现 PHP 多版本共存

这里我们以同时安装 PHP-7.2 和 PHP-5.6 两个版本为例,说明Debian环境中如何配置实现Nginx中的PHP多版本共存。

一、根据安装配置PHP7.2教程安装 PHP-7.2 和 PHP-5.6:

#先安装 PHP7.2
apt install -y php7.2-fpm php7.2-mysql php7.2-curl php7.2-gd php7.2-mbstring php7.2-xml php7.2-xmlrpc php7.2-zip php7.2-opcache

#接着安装 PHP5.6
apt install -y php5.6-fpm php5.6-mysql php5.6-curl php5.6-gd php5.6-mbstring php5.6-mcrypt php5.6-xml php5.6-xmlrpc php5.6-zip php5.6-opcache

二、设置虚拟主机使用的PHP版本
在需要使用 PHP7.2 的虚拟主机下使用(注意fastcgi_pass这里的不同):

##PHP
  location ~ \.php$ {
      fastcgi_pass unix:/run/php/php7.2-fpm.sock;
      fastcgi_index index.php;
      include fastcgi.conf;
      fastcgi_param PHP_VALUE "open_basedir=$document_root:/tmp/:/proc/";
    }

在需要使用 PHP5.6 的虚拟主机下使用:

##PHP
  location ~ \.php$ {
      fastcgi_pass unix:/run/php/php5.6-fpm.sock;
      fastcgi_index index.php;
      include fastcgi.conf;
      fastcgi_param PHP_VALUE "open_basedir=$document_root:/tmp/:/proc/";
    }

然后重启 Nginx,

systemctl reload nginx

就是这么简单粗暴,基本上,只需要改动一个PHP的版本号,就设置好了。

文章末尾固定信息

继续阅读
 
joseph
  • 本文由 joseph 发表于 2017年12月16日
  • 除非特殊声明,本站文章许可协议为"署名-非商用-相同方式共享 4.0",转载请保留原链、作者等信息。
广告也精彩
匿名

发表评论

匿名网友
:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:
确定

拖动滑块以完成验证