Skip to main content

INSTALLING/UPGRADING/DOWNGRADING PHP ON UBUNTU


        This helps you to install lower or higher versions of php in your ubuntu server other than the default one.If you already have higher version installed on your system and if you need to install lower version, then you have to remove higher version first and remove apt repository from system.

INSTALLING PHP 5.6 ON UBUNTU

#apt-get install python-software-properties
# sudo add-apt-repository ppa:ondrej/php
# sudo apt-get update
# sudo apt-get install -y php5.6

Check Installed PHP Version:
# php -v

We can see version of php as 5.6


 INSTALLING PHP 7.1 ON UBUNTU

#apt-get install python-software-properties
#add-apt-repository ppa:ondrej/php
#apt-get update
#apt-get install -y php7.1

Check Installed PHP Version:
 #php -v



If you have installed multiple php versions and want to use different than default. Use following steps to switch between php5.6 and php7.1 version. You can use the same command for other php versions.

From php 5.6 to 7.1

#a2dismod php5.6
This disables php 5.6. Now we wamt to enable php 7.1

#a2enmod php7.1

Inorder to make it effective we have to restart apache2 service
#service apache2 restart

#update-alternatives --set php /usr/bin/php7.1




Similarly we can also do it for php 7.1 to php 5.6. 
From PHP 7.1 to 5.6

 #a2dismod php7.1
#a2enmod php5.6
#service apache2 restart

#update-alternatives --set php /usr/bin/php5.6

 Eventhough this blog explains only about php5.6 and php7.1 it is also applicable to other php versions.