After trying a couple of packages, settings and configuration, finally I seem to have found out a working solution:
Please note the repository is as stated above and not as:
ppa:ondrej/php5-5.6 because this has been deprecated where the above PPA is a co-installable one, meaning you can install PHP 5.5, PHP 5.6 or PHP 7.0 as per your requirement.
Press enter to confirm. If you come across any error then you will need to install python-software-properties first as shown below:
1. Update your PPA repository with the PHP 5.6 package sources:
sudo add-apt-repository ppa:ondrej/php
Please note the repository is as stated above and not as:
ppa:ondrej/php5-5.6 because this has been deprecated where the above PPA is a co-installable one, meaning you can install PHP 5.5, PHP 5.6 or PHP 7.0 as per your requirement.
Press enter to confirm. If you come across any error then you will need to install python-software-properties first as shown below:
sudo apt-get update
sudo apt-get install python-software-properties
2. Update
Once again update your packages: sudo apt-get update
3. Install PHP 5.6 and its relevant mods:
sudo apt-get install php5.6 php5.6-mbstring php5.6-mcrypt php5.6-mysql php5.6-xml
sudo apt-get install php7.0 # for PHP 7.0
sudo apt-get install php5.5 # for PHP 5.5
4. Disable PHP 5.5:
Now this step is very important else you won't be able to use PHP 5.6. Even when you check your PHP version, it will still display as PHP 5.5. Follow the step below to disable PHP 5.5. sudo a2dismod php5
5. Enable PHP 5.6:
sudo a2enmod php5.6
6. Restart Apache web server:
sudo service apache2 restart