PHP 5.6

If for some reason you need to downgrade your PHP version (to PHP 5.6) you can get it done by following this really short tutorial. Naturally you can downgrade from PHP 7 (as in this example), PHP 7.1 or even 7.2 if needed.


First let’s connect to your server and get the basics done (if you haven’t done so already).

# sudo apt-get install python-software-properties

So now we need to add the repository for PHP 5.6:

# sudo add-apt-repository -y ppa:ondrej/php

Then update your APT package list:

# sudo apt-get update

Time to install PHP 5.6 (FPM):

# sudo apt-get install php5.6-fpm

P.S. If you need those standard PHP 5.6 addons here is what you need to add on this step:
# sudo apt-get install libapache2-mod-php5.6 php5.6-curl php5.6-gd php5.6-mbstring php5.6-mcrypt php5.6-mysql php5.6-xml php5.6-xmlrpc

Now let’s see what we are currently running:

# php -v
PHP 7.0.4-7ubuntu2.1 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies

So as you can see from the example above we are not quite finished yet… But fear not, there are only three more commands to go:

# sudo mv /usr/bin/php /usr/bin/php7
# sudo mv /usr/bin/php5.6 /usr/bin/php

And now you should check your PHP version again:

# php -v
PHP (cli)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies

There we go! Almost done, now the only thing left to do is to reboot Apache:

# service apache2 restart

Finished! now it is time to start working on that code!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.