[教程]Ubuntu 下轻松实现 PHP 多版本共存

来源:互联网 发布:夏天披肩款式图淘宝网 编辑:程序博客网 时间:2024/06/11 21:49

原文地址



随着 php-mysql 拓展在 PHP7 被砍掉以后,一些程序或者插件就不能运行在 PHP7 上,因此 PHP 多版本的需求就显得非常的有必要。 
因为系列教程中 PHP 是通过软件源非编译安装的,所以实现多版本共存就非常的方便,而且还非常浪费时间,编译一个php那可是大半个小时啊!!。 
 
教程 
 
 
这里以安装 PHP7.1 和 PHP5.6 多版本为例。 
 
 
一、根据 Ubuntu 免编译安装 PHP-FPM 教程进行安装 PHP7.1 和 PHP7.1 和 PHP5.6: 

复制代码
  1. 先安装 PHP7.1
  2. 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
  3. 再接着安装 PHP7.0
  4. apt install php7.0-fpm php7.0-mysql php7.0-curl php7.0-gd php7.0-mbstring php.07-mcrypt php7.0-xml php7.0-xmlrpc php7.0-zip php7.0-opcache -y
  5. 再接着安装 PHP5.6
  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
 
 
 
二、设置虚拟子主机反代的版本, 
在需要使用 PHP7.1 的子主机下使用: 
 
 
复制代码
  1. ##PHP
  2.   location ~ [^/]\.php(/|$) {
  3.       fastcgi_pass unix:/run/php/php7.1-fpm.sock;
  4.       fastcgi_index index.php;
  5.       include fastcgi.conf;
  6.       fastcgi_param PHP_VALUE "open_basedir=$document_root:/tmp/:/proc/";
  7.     }
 
 
在需要使用 PHP7.1 的子主机下使用: 
 
 
复制代码
  1. ##PHP
  2.   location ~ [^/]\.php(/|$) {
  3.       fastcgi_pass unix:/run/php/php7.0-fpm.sock;
  4.       fastcgi_index index.php;
  5.       include fastcgi.conf;
  6.       fastcgi_param PHP_VALUE "open_basedir=$document_root:/tmp/:/proc/";
  7.     }
 
 
 
 
 
 
在需要使用 PHP5.6 的子主机下使用:  
 
 
复制代码
  1. ##PHP
  2.   location ~ [^/]\.php(/|$) {
  3.       fastcgi_pass unix:/run/php/php5.6-fpm.sock;
  4.       fastcgi_index index.php;
  5.       include fastcgi.conf;
  6.       fastcgi_param PHP_VALUE "open_basedir=$document_root:/tmp/:/proc/";
  7.     }
 
 
 
然后重启 OpenResty:
复制代码
  1. nginx -s reload
 
 
就是这么简单粗暴,基本上一下子就设置好了。 
 
无论是编译的还是软件包安装的 Nginx 及其衍生版都可以使用这种方法快速设置多版本 

原文地址


原创粉丝点击