How to downgrade/upgrade from PHP 7 to PHP 5.6 and vice versa on Ubuntu 16.04

By default on Ubuntu 16, LAMP Stack comes with PHP 7, But sometimes we need lower or higher version of PHP to support our application. To get php 5.6 or php 7 we don't need to remove other version of php. we can just install other version as well can switch between the php versions.

Follow the below steps to upgrade php 7.0 to php 5.6 or php 5.6 to php 7.0

Add the ppa in repository

sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
Install required the version of php
sudo apt-get install php7.0 php5.6 php5.6-mysql php-gettext php5.6-mbstring php-mbstring php7.0-mbstring php-xdebug libapache2-mod-php5.6 libapache2-mod-php7.0
From php5.6 to php7.0
sudo a2dismod php5.6
sudo a2enmod php7.0
sudo service apache2 restart
2. From php7.0 to php5.6
sudo a2dismod php7.0
sudo a2enmod php5.6
sudo service apache2 restart
3. Check the current active version of PHP on your system
php -v
That's it
Comments are closed