While trying to install PHP to Ubuntu 16.04 LTS, I encountered a weird issue where the version being installed is PHP 7.0. Now, the reason I am launching this server is because I want to install Phabricator by Phacility and, as of press time, it does not support nor run in PHP 7.

Note, it might seem that you are installing PHP 5.X just because you are running say sudo apt-get install php5-cli, but in reality, you are actually installing PHP 7. How do I know? Check out the packages to be installed before confirming! If you look closely at the following example clause, you will see that what Ubuntu is trying to install is PHP 7.

Now, like what any Geekysaur would do, we would look for workarounds! What better workaround is there than to install a lower version of PHP?! To start, just run:

This would basically remove all packages that contain the string php and cause its related config to be deleted. The wanted effect is that it would now not allow us to install any of the PHP packages.

Next, we need to add the Personal Package Archives (PPA) and we’d be using the one hosted by ondrej. To do that, just run sudo add-apt-repository ppa:ondrej/php. What this does is it adds a location where all future PHP packages would be taken from. Imagine, we just lost the PHP 7 packages, now we have the PHP 5.X packages!

After that, just run sudo apt-get update to fetch and update the repositories and start installing PHP 5.5 or 5.6! Just type in sudo apt-get install <package_name> replacing <package_name> with any of the following:

Wew! That was easy! Did you encounter issues or need any other help? Were you able to successfully install PHP 5.X? Hit us up in Facebook or the comments below!