Sometimes, you might need to downgrade your PHP version on Ubuntu 22.04 for compatibility reasons or to resolve issues with your web applications. This step-by-step guide will walk you through the process of downgrading PHP while ensuring a smooth transition.
Before you begin, ensure you have the following:
- A Ubuntu 22.04 server with PHP installed.
- Administrative access to your server via SSH.
Step 1: Check Your Current PHP Version
To identify your current PHP version, open a terminal and run:
This command will display the installed PHP version. Make a note of it.
Step 2: Add a PPA for the Desired PHP Version
Since Ubuntu 22.04 may not have the older PHP versions in its official repositories, you can use a Personal Package Archive (PPA) to obtain the version you want. Replace
X.Y with the specific PHP version you need:
sudo add-apt-repository ppa:ondrej/php
Step 3: Update the Package List
Update the package list to include the PHP version from the newly added PPA:
sudo apt update
Step 4: Install the Desired PHP Version
Install the desired PHP version and its dependencies. For example, if you want to downgrade to PHP 7.4, use the following command. Adjust the version number accordingly:
sudo apt install php7.4
Step 5: Disable the Current PHP Version
Before switching to the new PHP version, you need to disable the current one. This prevents conflicts and ensures a smooth transition:
sudo a2dismod phpX.Y
X.Y with the version you noted in Step 1.
Step 6: Enable the Newly Installed PHP Version
Now, enable the newly installed PHP version:
sudo a2enmod php7.4
Step 7: Restart the Web Server
To apply the changes, restart your web server. If you’re using Apache, use the following command:
sudo systemctl restart apache2
For Nginx, use:
sudo systemctl restart nginx
Step 8: Verify the PHP Version
Confirm that you’ve successfully downgraded PHP by running:
This command should display the version you installed in Step 4.
Step 9: Test Your Web Applications
It’s crucial to thoroughly test your web applications to ensure they function correctly with the downgraded PHP version. Look for any compatibility issues or unexpected behavior.
Downgrading PHP on Ubuntu 22.04 can be necessary for maintaining web application compatibility. By following this step-by-step guide, you can safely and effectively switch to the desired PHP version while ensuring your web server continues to operate smoothly.