This example explains how to assign a different PHP version per directory. It can also be adapted to add Python support by running the Python interpreter as fast_cgi
on a particular port.
For the purpose of the example, I assume there is a separate directory for each PHP version and they are named according to the PHP version that runs them, but this can be adjusted.
mkdir /home/user/www
mkdir /home/user/www/5.6.5
mkdir /home/user/www/7.0.2
mkdir /home/user/www/7.0.4
mkdir /home/user/www/7.0.6
Create symbolic links to directories that should be handled by different PHP versions:
sudo ln -s /home/user/www/7.0.2/ /var/www/html/7.0.2
sudo ln -s /home/user/www/7.0.4/ /var/www/html/7.0.4
sudo ln -s /home/user/www/7.0.6/ /var/www/html/7.0.6
Then add the following lines to /etc/apache2/sites-enabled/000-default.conf in default virtual host *:80
(For your needs, you can set up one more FastCGI handler here for the website that requires Python). I assume PHP 5.6.5 runs on port 9999, 7.0.2
runs on port 9998
, etc.
DirectoryIndex index.html index.php
ProxyPassMatch ^/5.6.5/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9999/var/www/html/
ProxyPassMatch ^/7.0.2/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9998/var/www/html/
ProxyPassMatch ^/7.0.4/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9997/var/www/html/
ProxyPassMatch ^/7.0.6/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9996/var/www/html/
Assuming your server is pointed by example.com
, you can test it on:
http://example.com/5.6.5/
http://example.com/7.0.2/
http://example.com/7.0.4/
http://example.com/7.0.6/