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.
1 2 3 4 |
The following additional packages will be installed: libc-client2007e libcurl3 libmcrypt4 mlock php-xml php7.0-cli php7.0-common php7.0-curl php7.0-fpm php7.0-imap php7.0-intl php7.0-json php7.0-mbstring php7.0-mcrypt php7.0-opcache php7.0-readline php7.0-xml |
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:
1 |
sudo apt-get purge `dpkg -l | grep php| awk '{print $2}' |tr "\n" " "` |
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
php5.5 php5.5-mcrypt php5.6-bcmath php5.6-mysql php5.5-bcmath php5.5-mysql php5.6-bz2 php5.6-odbc php5.5-bz2 php5.5-odbc php5.6-cgi php5.6-opcache php5.5-cgi php5.5-opcache php5.6-cli php5.6-pgsql php5.5-cli php5.5-pgsql php5.6-common php5.6-phpdbg php5.5-common php5.5-phpdbg php5.6-curl php5.6-pspell php5.5-curl php5.5-pspell php5.6-dba php5.6-readline php5.5-dba php5.5-readline php5.6-dev php5.6-recode php5.5-dev php5.5-recode php5.6-enchant php5.6-snmp php5.5-enchant php5.5-snmp php5.6-fpm php5.6-soap php5.5-fpm php5.5-soap php5.6-gd php5.6-sqlite3 php5.5-gd php5.5-sqlite3 php5.6-gmp php5.6-sybase php5.5-gmp php5.5-sybase php5.6-imap php5.6-tidy php5.5-imap php5.5-tidy php5.6-interbase php5.6-xml php5.5-interbase php5.5-xml php5.6-intl php5.6-xmlrpc php5.5-intl php5.5-xmlrpc php5.6-json php5.6-xsl php5.5-json php5.5-xsl php5.6-ldap php5.6-zip php5.5-ldap php5.5-zip php5.6-mbstring php5.5-mbstring php5.6 php5.6-mcrypt |
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!
I’m getting below trying to install php5.5
The following packages have unmet dependencies:
php-yac : Conflicts: php-xcache but 3.2.0-2+deb.sury.org~xenial+1 is to be installed
Hi Krzysztof! My apologies for the uber late reply. If you’re trying to install and are having unmet dependencies, just do an apt-get install then try again.