PHP is a popular server-side scripting language used for web development. With the release of PHP 8, many developers have upgraded their systems to take advantage of its new features. However, some developers have found that the latest version is not compatible with their existing applications or systems. In such cases, downgrading to an earlier version of PHP can be an effective solution.
In this article, we’ll provide a step-by-step guide to downgrading from PHP 8 to PHP 7 on Ubuntu.
Step 1: Enable PHP 7 repository
Next, you’ll need to add the repository for PHP 7 to your system. To do this, you’ll need to run the following commands:
sudo apt update
sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update
Step 2: Install PHP 7
Once the repository for PHP 7 has been added to your system, you can install it using the following command:
sudo apt install php7.4
Step 3: Set PHP 7 as Default
Ubuntu allows us to install and use multiple php versions on a single system. You can simply set any version to use as the default version without uninstalling others.
sudo alternatives --config php
This will show you a list of install PHP version as below:
Enter the selection number to make any php version as default. For example, to set PHP 7.4 as default, input “1” and hit enter.
Step 4: Check the installed version of PHP
To verify that PHP 7 has been installed, run the following command:
This should display the version of PHP that is currently installed on your system.
OutputPHP 7.4.33 (cli) (built: Nov 8 2022 11:33:35) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies with Zend OPcache v7.4.33, Copyright (c), by Zend Technologies
Step 5: Configure PHP 7
Finally, you’ll need to configure PHP 7 to work with your system and applications. You can do this by editing the php.ini file using the following command:
sudo nano /etc/php/7.4/cli/php.ini
You can make any necessary changes to the file and then save it.
In conclusion, downgrading from PHP 8 to PHP 7 on Ubuntu can be a straightforward process if you follow these steps carefully. By downgrading, you can ensure that your existing applications and systems continue to work as expected, while taking advantage of the stability and compatibility offered by PHP 7.