How to install PHP 5.6 in Ubuntu 16

In Ubuntu 16, installing PHP with apt-get install php installs PHP version 7, so to install PHP 5.6, you can add a third-party repository.

If the system has PHP 7 installed, then you can delete all of its components like this:

sudo apt-get purge `dpkg -l | grep php| awk '{print $2}' |tr "\n" " "`

Now add a third-party source:

sudo apt-get install software-properties-common
sudo add-apt-repository ppa:ondrej/php

And install from it PHP 5.6:

sudo apt-get update
sudo apt-get install php5.6

Similarly, you can install modules, for example:

sudo apt-get install php5.6-mysql php5.6-mcrypt php5.6-mbstring php5.6-xml

To check the installed version of PHP, perform:

sudo php -v

Leave a Reply