Ubuntu 下轻松实现 PHP 多版本共存
本文最后更新于 2490 天前,其中的信息可能已经有所发展或是发生改变。

介绍

随着 php-mysql 拓展在 PHP7 被砍掉以后,一些程序或者插件就不能运行在 PHP7 上,因此 PHP 多版本的需求就显得非常的有必要。

因为系列教程中 PHP 是通过软件源非编译安装的,所以实现多版本共存就非常的方便。

教程

这里以安装 PHP7.1 和 PHP5.6 多版本为例。

一、根据 Ubuntu 免编译安装 PHP-FPM 教程进行安装 PHP7.1 和 PHP5.6:

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

再接着安装 PHP5.6

apt install 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 -y

二、设置虚拟子主机反代的版本,参考:OpenResty 创建虚拟子主机并开启 PHP-FPM 设置防跨站

在需要使用 PHP7.1 的子主机下使用:

 ##PHP
  location ~ [^/]\.php(/|$) {
      fastcgi_pass unix:/run/php/php7.1-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/";
    }

然后重启 OpenResty:

nginx -s reload

就是这么简单粗暴,基本上一下子就设置好了。

评论

  1. 7年前
    2017-7-02 21:33:02

    还有这种操作 /捂脸

    • 妙正灰
      博主
      MikuSama
      7年前
      2017-7-03 17:10:46

      这下被你知道了

本文评论已关闭
上一篇
下一篇