Install Multiple PHP Versions on Ubuntu 16.04
As a default, Ubuntu 16.04 LTS servers assign the PHP 7.0 version. Though PHP 5.6 is coming to the end of life in December of 2018, some applications may not be compatible with PHP 7.0. For this tutorial, we instruct on how to switch between PHP 7.0 and PHP 5.6 for Apache and the overall default PHP version for Ubuntu.
Install PHP 5.6
Step 1: Update Apt-Get
As always, we update and upgrade our package manager before beginning an installation. If you are currently running PHP 7.X, after updating apt-get, continue to step 2 to downgrade to PHP 5.6.
Step 2: Install PHP 5.6
Install the PHP5.6 repository with these two commands.
PHP Version for Apache
Step 3: Switch PHP 7.0 to PHP 5.6
Switch from PHP 7.0 to PHP 5.6 while restarting Apache to recognize the change:
Verify that PHP 5.6 is running on Apache by putting up a PHP info page. To do so, use the code below in a file named as infopage.php and upload it to the /var/www/html directory.
By visiting http://xxx.xxx.xxx.xxx/infopage.php (replacing the x’s with your server’s IP address), you’ll see a PHP info banner similar to this one, confirming the PHP Version for Apache:
Continue onto the section PHP Version for Ubuntu to edit the PHP binary from the command line.
PHP Version for Ubuntu
Step 4: Edit PHP Binary
Maintenance of symbolic links or the /etc/alternatives path through the update-alternatives command.
Select php5.6 version to be set as default, in this case, its the number one option.
You can now verify that PHP 5.6 is the default by running: