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:
|
1 |
sudo apt-get install python-software-properties |
Add repository for PHP 5.6:
|
1 |
sudo add-apt-repository -y ppa:ondrej/php |
Update package lists:
|
1 |
sudo apt-get update |
Install php5-fpm:
|
1 |
sudo apt-get install php5.6-fpm |
And the result is:
|
1 2 3 4 5 |
root@ubuntu-512mb-fra1-01:~# php -v PHP 5.6.20-1+donate.sury.org~xenial+2 (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 |
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.
Pingback: Ubuntu 16.04 und PHP7 - ein Problem? - TECH STATE
And what about libapache2-mod-php5?
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.
Thank you for your reply
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.
Didn’t check this. I installed PHP 5 directly, without installing PHP 7 before.
Same problem is here, I followed each above instruction even after that i also getting php7.0.14. Please guide me thanks in advance……
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!
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.
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
php5-fpm doesn’t exist :/
This is a really horrible advice :(. Don’t mix Wily packages with Xenial packages. For better way follow the advice here: https://askubuntu.com/questions/761713/how-can-i-downgrade-from-php-7-to-php-5-6-on-ubuntu-16-04/761735
I suggest you take this down or at least edit this article, so it uses
ppa:ondrej/php, where PHP 5.5, PHP 5.6 and PHP 7.0 is available at the same time for Ubuntu 14.04 and higher.Thank you for your advice. I changed the article to make sure my old workaround isn’t used anymore.
No good. Missing PEAR and PECL. If you can’t install PEAR and PECL modules, PHP is pretty much useless in production.
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!
Can you help install php5-zip after this?
aptitude install php5.6-zip
$ 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
thank you , these commands worked on my ubuntu server,thank you so much
Pingback: Ubuntu How To Downgrade Php | Wabjayka
Newbies may need this line:
$sudo add-apt-repository ppa:ondrej/php
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