在同一台服务器上运行两个PHP版本 [英] Running two PHP versions on the same server

查看:178
本文介绍了在同一台服务器上运行两个PHP版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在本地服务器上有两个项目,一个项目正在运行PHP5.6,另一个项目正在运行PHP7.0.现在是否可以根据项目启用这两个版本?我已经尝试在项目htaccess之一中添加AddHandler application/x-httpd-php7 .php,但是它不起作用.当前,服务器上已经安装了PHP7.0和PHP5.6-fpm.下面是phpinfo的屏幕截图.

I have two projects on the local server, one project is running PHP5.6 and the other one is running PHP7.0. Now would it be possible to enable this two versions based on the projects? I already tried adding AddHandler application/x-httpd-php7 .php in one of the project htaccess but its not working. Currently, PHP7.0 and PHP5.6-fpm already installed on the server. Below is the screenshot of the phpinfo.

推荐答案

因此,在Google上搜索了整整一天.我设法在FastCgi中的不同php版本上运行我的两个项目.感谢来自这个论坛的人们.我卸载了包括Apache在内的所有内容,然后重新开始.下面是我用来在本地服务器上启用两个版本的PHP的步骤.顺便说一句,我的计算机在Linux Mint 18上运行.

So after searching on Google for the whole day. I managed to run my two projects in FastCgi on different php versions. Thanks to the guys from this forum. I uninstalled everything including Apache and start over again. Below are the steps I used to enable two versions of PHP on my local server. Btw, my computer is running on Linux Mint 18.

  1. 假设您已经安装了Apache,为这两个项目创建了虚拟主机,并添加了必要的php PPA.我们将项目称为PHP 5.6的项目site56.local和针对PHP 7.0的项目site70.local.通过运行以下命令安装php5.6-fpmphp7.0-fpm:

  1. Assuming you already installed Apache, created virtual host for the two projects and added the necessary php PPAs. Let's call the projects site56.local for PHP 5.6 and site70.local for PHP 7.0. Install php5.6-fpm and php7.0-fpm by running:

sudo apt-get install php5.6-fpm
sudo apt-get install php7.0-fpm

  • /usr/lib/cgi-bin/下创建两个文件(老实说,我不知道是否仍然需要执行此步骤),然后保存:

  • Create two files under /usr/lib/cgi-bin/ (honestly I don't know if this step is still necessary), and save:

    sudo nano /usr/lib/cgi-bin/php56-fcgi
    sudo nano /usr/lib/cgi-bin/php70-fcgi
    

  • 打开php56 conf文件/etc/apache2/conf-available/php5.6-fpm.conf,添加此配置并保存:

  • Open php56 conf file /etc/apache2/conf-available/php5.6-fpm.conf, add this config and save:

    <IfModule mod_fastcgi.c>
        AddHandler php56-fcgi .php
        Action php56-fcgi /php56-fcgi
        Alias /php56-fcgi /usr/lib/cgi-bin/php56-fcgi -socket /var/run/php/php5.6-fpm.sock -pass-header Authorization
        Action php70-fcgi /php70-fcgi
        Alias /php70-fcgi /usr/lib/cgi-bin/php70-fcgi -socket /var/run/php/php7.0-fpm.sock -pass-header Authorization
    </IfModule>
    <Directory /usr/lib/cgi-bin>
        Require all granted
    </Directory>
    

  • 现在启用新的apache配置:

  • Now enable the new apache config:

    sudo a2enconf php5.6-fpm
    

  • 如果您安装了php5.6和php5.7,请确保禁用这两个并重新启动apache:

  • If you installed php5.6 and php5.7, make sure you disable this two and restart apache:

    sudo a2dismod php5.6 php7.0
    sudo systemctl restart apache2
    

  • 在应该在php7.0上运行的项目上创建一个.htacces文件,并添加以下处理程序:

  • Create a .htacces file on the project that should run on php7.0 and add this handler:

    AddHandler php70-fcgi .php
    

  • 现在在两个项目上创建一个phpinfo文件,如果您看到类似的内容,那么恭喜您!

  • Now create a phpinfo file on the two projects and if you see something like this, then congratulations!

    PS:确保在apache2.conf或httpd.conf中启用htaccess

    PS: Make sure you enable htaccess in your apache2.conf or httpd.conf

    site56.local/phpinfo.php:

    site56.local/phpinfo.php:

    site70.local/phpinfo.php:

    site70.local/phpinfo.php:

    这篇关于在同一台服务器上运行两个PHP版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆