Running multiple versions of PHP on Ubuntu

Is there an easy way to run multiple versions of PHP on Ubuntu 10.04 (desktop), and switching between them?

I am spoiled with the very easy installation and switching of PHP in WAMP for Windows. This would be for a development environment.


Solution 1:

The idea would be to manually compile several versions of PHP (./configure, ./make but not ./make install), and have the PHP extension you request loaded within your VirtualHost configuration.

That way, you can postpone loading the PHP library until you need it, and you can choose a different PHP library for each VirtualHost.

Solution 2:

To avoid to install and configure two or more web server (listeing on two or more ports), try to read these:

  • how-can-one-run-multiple-versions-of-php-5-x-on-a-development-lamp-server
  • running-multiple-php-versions-on-a-single-apache-install

Solution 3:

I had the same problem when I was handling multiple projects. I referred this article But it was like every time I need to switch the versions if need but this gives the flexibility for cli and web separately.

Moving From php5.6 to php7.0

For Apache, we can use the command as:

sudo a2dismod php5.6 ; sudo a2enmod php7.0 ; sudo service apache2 restart

For CLI, we can use the command as:

sudo update-alternatives --set php /usr/bin/php7.0

Moving From php7.0 to php5.6

For Apache, we can use the command as:

sudo a2dismod php7.0 ; sudo a2enmod php5.6 ; sudo service apache2 restart

For CLI, we can use the command as:

sudo update-alternatives --set php /usr/bin/php5.6