PHP is a popular web development language used by many websites around the world. It releases frequent updates and improvements. However, sometimes you may need to downgrade PHP version of your system because of performance issues. Here is how to downgrade PHP 7 to 5.x. You can use them to downgrade 7.4, 7.3, 7.x to 5.6, 5.5, 5.x.
How to Downgrade PHP 7 to 5.x
Unfortunately, there is no direct command to downgrade PHP 7 to 5, since it is a downgrade of major version 7 to 5. You need to uninstall PHP 7 and install PHP 5 afresh. Here are the steps to downgrade PHP 7 to 5.6.
1. Uninstall PHP 7
Open terminal and run the following command to uninstall PHP 7.
$ sudo apt-get remove -y –purge php7.0*
Replace 7.0* above with your PHP version. For example, if you want to uninstall PHP 7.4 then run
$ sudo apt-get remove -y –purge php7.4
If you don’t know your PHP version, run the following command
$ sudo php -v
Also read : How to Rename Multiple Files in Linux
2. Add PHP Repository
By default, the repository containing PHP 5 files are not present in source list of Ubuntu/Debian systems. So we will add that repository to our source list.
$ sudo add-apt-repository –remove ppa:ondrej/php
Also read : How to Install Squid Proxy Server in Linux
3. Update Packages
Update system packages with the following command.
$ sudo apt-get update
4. Install PHP 5
Run the following command to install PHP 5 and PHP-FPM 5.
$ sudo apt-get install php5-fpm php5-mysql
Replace php5 above with the desired version of your PHP above. For example, if you want to install PHP 5.6 run the following command
$ sudo apt-get install php5.6-fpm php5.6-mysql
Also read : How to Extract .bz2 file in Linux
5. Switch PHP Version in Server
Run the following command to switch PHP version 7 to 5.6 in Apache Server. Replace php7.0 and php5.6 with your old and new PHP versions respectively.
$sudo a2dismod php7.0
$sudo a2enmod php5.6
$sudo service apache2 restart
If you run PHP via NGINX, open its configuration file
$ sudo vi /etc/nginx/nginx.conf
Look for the following line. Replace php7.0 with the PHP version of old installation (e.g php7.4 for PHP 7.4)
fastcgipass unix:/var/run/php/php7.0-fpm.sock
Change it to the following. Replace php5 with the PHP version of new installation (e.g php5.6 for PHP 5.6)
fastcgipass unix:/var/run/php5.6-fpm.sock;
That’s it. Your PHP version will be downgraded.
Also read : How to View Hidden Files in Linux
Related posts:
Sreeram has more than 10 years of experience in web development, Python, Linux, SQL and database programming.