当前位置首页 > Debian知识

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

阅读次数:193 次  来源:admin  发布时间:

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的版本号,就设置好了。

原文发布时间:2017-12-16 本文来自云栖社区合作伙伴“Debian社区”,了解相关信息可以关注“Debian社区”。
上一篇:InstallationofOracle9i(R2)onFedoraCoreLinux2,3,4,5and6
下一篇:Debian里编译内核