, ,

How to Downgrade PHP Version on Ubuntu: Step-by-Step Guide

Posted by

Downgrading the PHP version on an Ubuntu server involves several steps. Below is a detailed guide on how to achieve this:

Step 1: Check the Current PHP Version

Run the following command to check the current PHP version installed:

php -v

Step 2: List Available PHP Versions

Before downgrading, you should check which PHP versions are available. Add the repository that contains multiple PHP versions:

sudo add-apt-repository ppa:ondrej/php
sudo apt update

Now, list the available PHP versions:

apt-cache showpkg php

Step 3: Install the Desired PHP Version

Install the desired PHP version (for example, PHP 8.1), you can run:

sudo apt install php8.1

If you need specific PHP extensions, install them as well. For example:

sudo apt install php8.1-mysql php8.1-xml php8.1-gd php8.1-mbstring

Step 4: Disable the Current PHP Version

If you have a newer PHP version enabled, disable it. For example, if you have PHP 8.2

sudo a2dismod php8.2

Step 5: Enable the Desired PHP Version

Enable the PHP version you just installed. For example, to enable PHP 8.1:

sudo a2enmod php8.1

Step 6: Update Alternatives

Set the newly installed PHP version as the default

sudo update-alternatives --set php /usr/bin/php8.1
sudo update-alternatives --set phar /usr/bin/phar8.1
sudo update-alternatives --set phar.phar /usr/bin/phar.phar8.1

Step 7: Restart Apache/Nginx

Restart your web server to apply the changes:

For Apache:

sudo /opt/lampp/lampp restart

Step 8: Verify the PHP Version

Finally, verify that the correct PHP version is now in use:

By following these steps, you should be able to downgrade the PHP version on your Ubuntu server successfully. If you encounter any issues, ensure all dependencies and configurations are properly adjusted to match the PHP version you are downgrading to.

4 4 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x