Add the ppa
sudo add-apt-repository ppa:ondrej/php5-5.6
Then install python-software-properties first to avoid some errors that might occur
sudo apt-get update
sudo apt-get install python-software-properties
Then install php
sudo apt-get update
sudo apt-get install php5
To switch to different php versions,assuming you are using both php5.6
and php7.0
Using apache you can do
sudo a2dismod php5.6 ##To use php5.6
sudo a2enmod php7.0 ##To use php7.0
sudo service apache2 restart
2
solved How to install PHP5 in Ubuntu 16 Virtual Box guest on Windows 10 host? [closed]