Step 1: Check versions
# check PHP version
php -v
# check Apache version
apache2 -v
If your Apache version is 2.2, follow Step 2; if version is 2.4, skip to Step 3
Step 2: Add PHP5.6+ repository and update package list
add-apt-repository ppa:ondrej/apache2apt-get updateapt-get upgrade
This step will upgrade Apache from 2.2 to 2.4. Re-configure your Apache if needed. Backup your existing Apache configurations, enabled sites and mods. You might need to re-install / upgrade some of the mods.
Step 3: Add PHP5.6+ Repository
add-apt-repository ppa:ondrej/phpapt-get update
Step 4: Install PHP 5.6
apt-get install -y php5.6 php5.6-mcrypt php5.6-mbstring php5.6-curl php5.6-cli php5.6-mysql php5.6-gd php5.6-intl php5.6-xsl php5.6-zip libapache2-mod-php5.6
This will install PHP 5.6 and some common packages such as cURL (php5.6-curl) and GD (lib5.6-gd), as well as enable PHP 5.6 in Apache 2.4 (libapache2-mod-php5.6).
Apache will be restarted during the process.
That’s all steps you have to do.
sudo a2dismod php5
sudo a2enmod php5.6
sudo service apache2 restart
Happy Coding! :)