How to downgrade PHP7 to PHP5.x ?

January 30, 2016 67.1k views
LAMP Stack PHP Apache Ubuntu

I upgrade my PHP in LAMP Ubuntu 14 server to PHP 7 following the tutorial - https://www.digitalocean.com/community/tutorials/how-to-upgrade-to-php-7-on-ubuntu-14-04

However after testing the application for 2 days, I wanted to downgrade it back to the original php version because of many unexpected errors in composer packages.

Image : http://i.imgur.com/MS2Q2Nz.png

Would be helpful if anyone can share the details.

2 comments
5 Answers

From php5.6 to php7.0:
Apache:
sudo a2dismod php5.6 ; sudo a2enmod php7.0 ; sudo service apache2 restart
CLI:
sudo update-alternatives --set php /usr/bin/php7.0
From php7.0 to php5.6:
Apache:
sudo a2dismod php7.0 ; sudo a2enmod php5.6 ; sudo service apache2 restart
CLI:
sudo update-alternatives --set php /usr/bin/php5.6

This worked for me:

  • sudo apt-get remove -y --purge php7.0*
  • sudo add-apt-repository --remove ppa:ondrej/php
  • back php7 nginx conf
  • edit nginx conf to run php5:
    change: fastcgipass unix:/var/run/php/php7.0-fpm.sock
    to: fastcgi
    pass unix:/var/run/php5-fpm.sock;

  • sudo apt-get update

  • install php5:
    sudo apt-get install php5-fpm php5-mysql

This work fine for me

From php5.6 to php7.0 :
Apache:
sudo a2dismod php5.6 ; sudo a2enmod php7.0 ; sudo service apache2 restart
CLI:
update-alternatives --set php /usr/bin/php7.0
from php7.0 to php5.6 :
Apache:
sudo a2dismod php7.0 ; sudo a2enmod php5.6 ; sudo service apache2 restart
CLI:
sudo update-alternatives --set php /usr/bin/php5.6

I am getting this error while installing php5-fpm on ubuntu 16.04 nginx server after removing php7 Package php5-fpm is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

Package php5-MySQL is not available but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'php5-fpm' has no installation candidate
E: Package 'php5-mysql' has no installation candidate

There's any complication if i change the php version? my databases will remain?

Have another answer? Share your knowledge.