Installing PHP 5.6 on Ubuntu 14.x, Ubuntu 16.x and Ubuntu 17.x has become easy, thanks to the ondrej/php repository (https://launchpad.net/~ondrej).
How to install PHP 5.6 on Ubuntu 14.x, Ubuntu 16.x and Ubuntu 17.x ?
To install PHP 5.6, simply execute the following sequence of commands:
apt-get install python-software-properties add-apt-repository ppa:ondrej/php apt-get update apt-get install php5.6
Note that if you want to install PHP 7.x, for example, all you have to do is change the php5.6 argument in the command to php7.0, php7.1 and so on…
To switch the version between PHP 5.6 and PHP 7.0:
a2dismod php5.6 a2enmod php7.0 service apache2 restart