Skip to content
Ubuntu Linux

How to Downgrade PHP Version on Ubuntu 24.04

Richard
Written by
Richard
Updated 3 min read
How to Downgrade PHP Version on Ubuntu 24.04
How to Downgrade PHP Version on Ubuntu 24.04

This article explains how to downgrade the version of PHP on Ubuntu 24.04.

PHP is a popular open-source scripting language ideal for web development. It can be embedded into HTML, enabling the creation of dynamic web pages, database interactions, and effective management of server-side tasks.

If the version of PHP you have installed is not compatible with some of your applications and services, you can downgrade to an earlier version. Reverting to an older version can help resolve issues and ensure the smooth operation of legacy code or specific third-party services that depend on those older versions.

The following steps will guide you through downgrading the PHP version in your environment.

⚡ Quick Answer

To downgrade PHP on Ubuntu 24.04, install PHP 8.2 with sudo apt install php8.2, then install matching modules such as php8.2-cli and php8.2-fpm. Run sudo a2dismod php8.3 and sudo a2enmod php8.2 for Apache, or point Nginx’s fastcgi_pass at php8.2-fpm.sock, then restart the web server.

Advertisement

Get PHP details

To downgrade PHP on Ubuntu, you must gather information about the current PHP version and its supporting modules.

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

Advertisement
🐘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.

Advertisement
🐘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

To downgrade to PHP version 8.2, you can install that version on your machine instead.

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

🐧Bash / Shell
sudo apt install php8.2
📝Good to KnowIf PHP 8.2 is unavailable in the default Ubuntu repositories, you can add a third-party PPA that provides this version.
Advertisement

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, gather the list of currently installed PHP modules and ensure that the appropriate versions for PHP 8.2 are installed.

📝Good to KnowObtain the list and execute the command, replacing version 8.3 with 8.2 for each module.
Advertisement
🐧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

You can use the command below to switch to the PHP version in Apache.

Disable the current PHP.

🐧Bash / Shell
sudo a2dismod php8.3

Enable the PHP version you want to use.

Advertisement
🐧Bash / Shell
sudo a2enmod php8.2

Restart Apache to apply the changes.

🐧Bash / Shell
sudo systemctl restart apache2.service

Switch PHP in Nginx

Open the server block file and update the PHP version when using an Nginx web server.

🐘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!

Advertisement

Conclusion:

In summary, downgrading the PHP version on Ubuntu 24.04 can be straightforward if you follow the necessary steps. Here are the key points to remember:

  • Check Current PHP VersionAlways start by verifying your existing PHP version.
  • List Installed PHP ModulesAssess which modules are currently installed to ensure compatibility with the older PHP version.
  • Install Older PHP VersionUse the appropriate commands to install the required older version of PHP, such as PHP 8.2.
  • Verify PHP and ModulesEnsure that the necessary PHP modules for the older version are correctly installed.
  • Configure Web ServerSwitch the PHP version as required depending on your web server (Apache or Nginx).
  • Restart ServicesAlways 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.

Have a question about this guide?

Answered by AI from this guide. Good questions may be added to this page — please don't include personal details.

Did this guide fix your problem?

Richard

About the Author

Richard

Tech Writer, IT Professional

Richard is a writer at Geek Rewind who turns complex IT tasks into clear, step-by-step guides. He draws on years of hands-on experience in system administration and enterprise IT operations, focusing on Windows, Linux and WordPress: the problems people actually run into, and the fixes that work. His server and WordPress guides come from systems he runs himself. Richard builds and maintains the platform behind Geek Rewind, from its Ubuntu servers and Nginx configuration to its custom WordPress plugins. Many new tutorials start with readers' questions, and he's always glad to answer them in the comments.

Advertisement

1 Comment

Leave a Comment

Your email address will not be published. Required fields are marked * How we handle comments