Skip to content

How to Downgrade PHP Version on Ubuntu 24.04

Richard
Written by
Richard
Mar 13, 2025 Updated Mar 20, 2026 4 min read
How to Downgrade PHP Version on Ubuntu 24.04

You can downgrade your PHP version on Ubuntu 24.04 to resolve compatibility issues with older applications or specific server-side code.

PHP is a popular server-side scripting language crucial for web development. Downgrading ensures your projects, which might depend on older PHP versions like 8.1 or 8.2, continue to function correctly.

This process allows you to switch from your current PHP installation to a desired older release on your Ubuntu 24.04 system.

⚡ Quick Answer

Install the desired PHP version using `sudo apt install phpX.Y`. Then, disable the current PHP module with `sudo a2dismod phpX.Y` and enable the new one with `sudo a2enmod phpX.Y`, restarting your web server afterward.

Get PHP details

Before you downgrade PHP on Ubuntu 24.04, it’s smart to check your current PHP version and see which modules are installed.

First, list the current version of PHP by running the command below.

🐘PHP
php --version
php -v

The command provided should produce an output similar to the example below. The currently installed version of PHP is [8.3.6].

🐘PHP
PHP 8.3.6 (cli) (built: Dec  2 2024 12:36:18) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.6, Copyright (c) Zend Technologies
with Zend OPcache v8.3.6, Copyright (c), by Zend Technologies

Next, execute the command below to check which PHP modules have been installed.

🐘PHP
dpkg --get-selections | grep -i php

The command above should output something similar to the one below. Here is a list of the PHP modules version currently installed on your system.

🐘PHP
php8.3-bcmath					install
php8.3-cli install
php8.3-common install
php8.3-curl install
php8.3-fpm install
php8.3-gd install
php8.3-imap install
php8.3-intl install
php8.3-ldap install
php8.3-mbstring install
php8.3-mysql install
php8.3-opcache install
php8.3-readline install
php8.3-soap install
php8.3-sqlite3 install
php8.3-xml install
php8.3-xmlrpc install
php8.3-zip install
......
......

Having collected PHP and all its required modules, you can now downgrade to a version compatible with your environment.

Install older version of PHP

Installing an older PHP version on Ubuntu 24.04 is straightforward, letting you switch to a specific version like PHP 8.2 if needed.

To install PHP version 8.2 on Ubuntu, run the command below.

🐧Bash / Shell
sudo apt install php8.2

If PHP 8.2 is unavailable in the default Ubuntu repositories, you can add a third-party PPA that provides this version.

Run the command below to add the repository.

🐧Bash / Shell
sudo add-apt-repository ppa:ondrej/php
sudo apt update

Once the package index has been added and refreshed, try installing PHP 8.2 again.

After installing PHP 8.2, you’ll want to check the list of currently installed PHP modules. Make sure the right versions for PHP 8.2 are installed. You can get the list and run the command, replacing ‘version 8.3’ with ‘8.2’ for each module. This way, you’ll have both versions installed.

🐧Bash / Shell
sudo apt install php8.2 php8.2-cli php8.2-commom php8.2-opcache php8.2-readline php8.2-bcmath php8.3-curl php8.2-gd					

Now you should have both [PHP 8.3] and [PHP 8.2] installed. However, your web server, such as Apache or Nginx, might still use PHP 8.3.

Switch PHP in Apache

To switch the PHP version for Apache, you’ll use the command below.

Disable the current PHP.

🐧Bash / Shell
sudo a2dismod php8.3

Enable the PHP version you want to use.

🐧Bash / Shell
sudo a2enmod php8.2

Restart Apache to apply the changes.

🐧Bash / Shell
sudo systemctl restart apache2.service

Switch PHP in Nginx

If you’re using Nginx, you’ll need to update its configuration to point to the new PHP version after you downgrade PHP on Ubuntu 24.04.

🐘PHP

location ~ .php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

Restart Nginx and PHP-FPM after making the changes.

🐧Bash / Shell
sudo systemctl restart nginx.service
sudo systemctl restart php8.2-fpm

That should do it!

Conclusion:

To sum up, downgrading your PHP version on Ubuntu 24.04 is quite manageable if you follow these steps. Here are the key points to remember:

  • Check Current PHP Version: Always start by verifying your existing PHP version.
  • List Installed PHP Modules: Assess which modules are currently installed to ensure compatibility with the older PHP version.
  • Install Older PHP Version: Use the appropriate commands to install the required older version of PHP, such as PHP 8.2.
  • Verify PHP and Modules: Ensure that the necessary PHP modules for the older version are correctly installed.
  • Configure Web Server: Switch the PHP version as required depending on your web server (Apache or Nginx).
  • Restart Services: Always restart your web server and PHP-FPM after making configuration changes to apply the updates.

By following these steps, you can effectively manage your PHP versions and maintain the stability of your applications.

How to degrade PHP version?

30. So now we will going to downgrade. It. So before that we need to come over into our file explorer. And then we need to go for our local C drive and then we need to go for zam.

How do I switch to a different version of PHP in Ubuntu?

To switch the default PHP version, use the sudo update-alternatives –config php command. For example: sudo update-alternatives –config php # There are 4 choices for the alternative php (providing /usr/bin/php).

Was this guide helpful?

Was this helpful?
Richard

About the Author

Richard

Tech Writer, IT Professional

Richard, a writer for Geek Rewind, is a tech enthusiast who loves breaking down complex IT topics into simple, easy-to-understand ideas. With years of hands-on experience in system administration and enterprise IT operations, he’s developed a knack for offering practical tips and solutions. Richard aims to make technology more accessible and actionable. He's deeply committed to the Geek Rewind community, always ready to answer questions and engage in discussions.

1 Comment

Leave a Comment

Your email address will not be published. Required fields are marked *

Exit mobile version