Ubuntu 16.04 Xenial: Downgrade PHP 7 to PHP 5.6

You got the latest Ubuntu Version 16.04 Xenial, but have trouble using PHP 7 because your application lacks support for it?

This tutorial shows you how to install PHP 5.6 on Ubuntu 16.04 Xenial.

Let’s assume you have a fresh Ubuntu 16.04 server.

Install add-apt-repository:

Add repository for PHP 5.6:

Update package lists:

Install php5-fpm:

And the result is:

Update 28-04-2016: thanks to Ondřej Surý for providing a better solution for installing PHP 5.6 on Ubuntu 16.04 LTS. I edited this article to make sure this better solutions is used.

22 thoughts on “Ubuntu 16.04 Xenial: Downgrade PHP 7 to PHP 5.6

  • Pingback: Ubuntu 16.04 und PHP7 - ein Problem? - TECH STATE

  • April 22, 2016 at 7:52 am
    Permalink

    And what about libapache2-mod-php5?

    Reply
    • April 22, 2016 at 7:59 am
      Permalink

      Never thought of that. I usually use nginx and FastCGI. And you could also use FastCGI on Apache. To decouple the Apache version from your PHP installation I would recommend to do so.

      But if I find some time I will check if the module version works.

      Reply
      • April 22, 2016 at 8:22 am
        Permalink

        Thank you for your reply

        Reply
  • April 23, 2016 at 1:53 pm
    Permalink

    Thank you for the quick tutorial. However everything loks good, but when I do a php -v I still get PHP7.0.4

    it also mention that php5-fpm is already the newest version, so I know it installed. I might missing another step. I looks like the system have both PHP installed, but is running PHP7 by default.

    Reply
    • April 23, 2016 at 2:09 pm
      Permalink

      Didn’t check this. I installed PHP 5 directly, without installing PHP 7 before.

      Reply
    • December 11, 2016 at 6:37 am
      Permalink

      Same problem is here, I followed each above instruction even after that i also getting php7.0.14. Please guide me thanks in advance……

      Reply
  • April 23, 2016 at 2:14 pm
    Permalink

    I don’t remember what version of PHP I had before, but I will say it wasn’t 7. I update Ubuntu 15.10 to 16.04 and one of my php projects is not running. The only thing I can see is that PHP7 is the version I have now.

    What would be the easiest way to make PHP5 default?

    Thanks for your help!

    Reply
    • April 23, 2016 at 2:52 pm
      Permalink

      If you had a old PHP version before and upgraded your Ubuntu installation, you automatically upgraded to PHP7. I would say you have to remove PHP7 before you install PHP5.6. But I can’t guarantee that this won’t break anything on your server, so handle with care.

      Reply
  • April 23, 2016 at 3:20 pm
    Permalink

    Daniel,

    I end up removing apache2, and php7 completely and then reinstall apache2, php5 and it worked. All this because of a project I’m working for a client and the old site didn’t work on PHP7, which it looks nice, but in this case I couldn’t use.

    Thank you for all the help.

    Jorge

    Reply
  • April 27, 2016 at 8:50 am
    Permalink

    php5-fpm doesn’t exist :/

    Reply
    • April 28, 2016 at 3:50 pm
      Permalink

      Thank you for your advice. I changed the article to make sure my old workaround isn’t used anymore.

      Reply
  • May 2, 2016 at 10:18 pm
    Permalink

    No good. Missing PEAR and PECL. If you can’t install PEAR and PECL modules, PHP is pretty much useless in production.

    Reply
  • May 14, 2016 at 7:09 am
    Permalink

    PHP Version still saying:
    PHP 7.0.4-7ubuntu2 (cli) ( NTS )

    So,, Do I have multiple versions now or only 5.6?
    If it’s only 5.6 so why it’s saying 7.0.4?
    If I have multiple so what’s the:
    Path to the PHP FastCGI binary
    Path to the php.ini directory
    -AND-
    Path to the PHP-FPM init script
    Path to the php.ini directory
    Path to the PHP-FPM pool directory

    So I can specify php version in ISPConfig 3
    Appreciated!

    Reply
    • August 23, 2016 at 3:12 pm
      Permalink

      aptitude install php5.6-zip

      Reply
  • May 27, 2016 at 8:19 am
    Permalink

    $ php -v
    PHP 7.0.6-13+donate.sury.org~xenial+1 (cli) ( NTS )
    Copyright (c) 1997-2016 The PHP Group
    Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
    with Xdebug v2.4.0, Copyright (c) 2002-2016, by Derick Rethans

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

    $ php -v
    PHP 5.6.22-1+donate.sury.org~xenial+1 (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

    Reply
    • July 15, 2016 at 4:02 am
      Permalink

      thank you , these commands worked on my ubuntu server,thank you so much

      Reply
  • Pingback: Ubuntu How To Downgrade Php | Wabjayka

  • July 11, 2016 at 8:58 am
    Permalink

    Newbies may need this line:

    $sudo add-apt-repository ppa:ondrej/php

    Reply
  • September 3, 2016 at 8:27 am
    Permalink

    Thanks. You just saved my arse!

    I needed it to run with Apache and MySQL too, so had to run

    $ sudo apt-get install libapache2-mod-php5.6
    $ sudo apt-get install mysql-server mysql-client php5.6-mysql

    Reply

Leave a Reply

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