How to Downgrade PHP 8.2 to 8.1 in Ubuntu

Websolutionstuff | Nov-01-2023 | Categories : PHP

Hey there, I recently found myself in a situation where I needed to downgrade my PHP version from 8.2 to 8.1 on my Ubuntu server. It's not as complicated as it may sound, and I'm here to guide you through the process step by step.

Whether you've encountered compatibility issues or simply need to switch back to PHP 8.1 for a specific project, this article will help you make the transition smoothly.

Let's get started with downgrading PHP 8.2 to 8.1 on Ubuntu!

Downgrading PHP from version 8.2 to 8.1 in Ubuntu involves several steps, including removing PHP 8.2 and installing PHP 8.1. Here's a step-by-step guide to help you with this process:

Step 1: Check Your Current PHP Version

Before downgrading, make sure you're running PHP 8.2. You can check your current PHP version using the command.

php -v

This command will display your PHP version. If it's 8.2, proceed with the downgrade.

 

Step 2: Remove PHP 8.2

First, remove PHP 8.2 and its related packages using the following commands.

sudo apt-get purge php8.2-common
sudo apt-get autoremove

 

Step 3: Add PHP 8.1 Repository

You need to add the repository for PHP 8.1. You can use the ondrej/php repository for this purpose.

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

 

Step 4: Install PHP 8.1

Now, install PHP 8.1 and the necessary PHP modules. You can install PHP and some commonly used extensions with the following command.

sudo apt-get install php8.1 php8.1-common php8.1-cli

You can also install additional PHP extensions depending on your project's requirements.

 

Step 5: Verify PHP 8.1 Installation

After the installation is complete, check the PHP version to make sure you're now running PHP 8.1.

php -v

It should display PHP 8.1.x.

 

Step 6: Update Your Web Server Configuration

If you are using a web server like Apache or Nginx, you'll need to update the configuration to use PHP 8.1. For Apache, you can use the following command to enable the PHP 8.1 module.

sudo a2enmod php8.1

For Nginx, you'll need to update your site configuration to use PHP 8.1

 

Step 7: Restart Your Web Server

After updating the web server configuration, restart your web server to apply the changes:

For Apache:

sudo systemctl restart apache2

For Nginx:

sudo systemctl restart nginx

 

Step 8: Test Your PHP Configuration

Create a PHP info file to test if PHP 8.1 is functioning correctly. Use a text editor to create a file named info.php in your web server's root directory (e.g., /var/www/html/), and add the following content:

<?php
phpinfo();
?>

Access this file from your web browser (e.g., http://your-server-ip/info.php) and verify that it shows PHP 8.1 information.

 

Step 9: Cleanup

You can remove the info.php file after testing, and you may also want to remove PHP 8.2-related configuration files if you no longer need them.

That's it! You've successfully downgraded PHP from version 8.2 to 8.1 on your Ubuntu server.

 


You might also like:

Recommended Post
Featured Post
The Mix Manifest Does Not Exist Laravel
The Mix Manifest Does Not Exis...

In this article, we will see the mix manifest does not exist in laravel 8 and laravel 9. We will solve the mix...

Read More

Oct-28-2022

Send Mail Example In Laravel 8
Send Mail Example In Laravel 8

In this article, we will see send mail in laravel 8. here we will see how to send mail in laravel 8. Emai...

Read More

Oct-16-2020

How To Get Current Week Records In MySQL
How To Get Current Week Record...

In this tutorial, we will see how to get current week records in MySQL. Many times we need to get current week reco...

Read More

Feb-07-2022

PHP - file_get_contents() SSL Connection Reset by Peer
PHP - file_get_contents() SSL...

Hey there! So, you're working with PHP and trying to fetch content from an HTTPS URL using the file_get_contents() f...

Read More

Mar-01-2024