Wednesday, June 14, 2017

How can I downgrade / Upgrade from PHP 7.0 to PHP 5.6 / PHP 5.6 to PHP 7.0 / PHP 8 on Ubuntu

Ubuntu 16.04 comes with php7.0, and some php web applications might fail to run  with php7.0. So, you test your web app with both php7.0 and php5.0  version. 

You can do following changes with Ubuntu sudo update-alternatives --config php
 
sudo apt install software-properties-common sudo add-apt-repository ppa:ondrej/php sudo apt update

root@pc1# apt-get install php7.0 php5.6 php5.6-mysql php-gettext php5.6-mbstring php-xdebug libapache2-mod-php5.6 libapache2-mod-php7.0 php5.6-curl php5.6-gd php5.6-mcrypt php5.6-xml php5.6-xmlrpc

sudo apt-get install php8.1 php8.1-fpm
sudo apt-get install php8.1-mysql php8.1-mbstring php8.1-xml php8.1-gd php8.1-curl
sudo apt-get install php7.4 php7.4-fpm
sudo apt-get install php7.4-mysql php7.4-mbstring php7.4-xml php7.4-gd php7.4-curl


Installing both php5.6 & php7.0 & php8.0 was clean in my case: no complain of issues, etc.

To switch from php7.0 to php5.6 or other:

# For php in web apps
sudo a2dismod php7.0 && sudo a2enmod php5.6 && sudo service apache2 restart
OR sudo update-alternatives --config php
# For php-cli in the command line
sudo ln -sfn /usr/bin/php5.6 /etc/alternatives/php
or from  php5.6 to php7:
# For php in web apps
sudo a2dismod php5.6 && sudo a2enmod php7.0 && sudo service apache2 restart
# For php-cli in the command line
sudo ln -sfn /usr/bin/php7.0 /etc/alternatives/php
Now Check php version : root@pc1# php --version or php -v
Remove : sudo apt-get remove php5.6-* 

2 comments: