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.
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
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
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>
Now enable the new apache config:
sudo a2enconf php5.6-fpm
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
Create a .htacces
file on the project that should run on php7.0 and add this handler:
AddHandler php70-fcgi .php
Now create a phpinfo file on the two projects and if you see something like this, then congratulations!
PS: Make sure you enable htaccess in your apache2.conf or httpd.conf
site56.local/phpinfo.php:
site70.local/phpinfo.php:
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…