dhduc
7/13/2017 - 9:35 AM

Use multiple PHP versions

Use multiple PHP versions

Use multiple PHP versions

You can use multiple PHP versions with one Apache server. Easily install them via the Apt package manager by the famous PPA from Ondrej. Then you can install multiple PHP versions like so:

sudo apt install php7.1 php5.6 php7.0

For being able to switch the PHP versions within the Apache webserver, you need the Lib Apache packages. You can install them like so:

sudo apt install libapache2-mod-php7.0
sudo apt install libapache2-mod-php7.1
sudo apt install libapache2-mod-php5.6

Afterwards you are able to switch the PHP version, which is being executed by Apache. E.g.:

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

To switch he PHP CLI version, you can use the "update-alternatives" command. This command let's choose you the various versions of your program. In the background it will create symlinks for you. For getting into the version chooser dialogue, execute the following command:

sudo update-alternatives --config php To switch PHP extensions for a specific PHP version, you can use the "phpenmod" and "phpdismod" commands. For enabling the Xdebug PHP extension for PHP 7.0, use the following command:

sudo phpenmod -v 7.0 xdebug

Reference