Skip to content
Follow
Ubuntu Linux

How to Downgrade PHP Version on Ubuntu 24.04

Richard
Written by
Richard
Mar 13, 2025 Updated Oct 10, 2026 8 min read
How to Downgrade PHP Version on Ubuntu 24.04
How to Downgrade PHP Version on Ubuntu 24.04

Advertisement

Install older version of PHP

Installing an older PHP version on Ubuntu 24.04 lets you run legacy code that fails on newer releases. You can add the third-party software repository to get past versions if they are missing from the default Ubuntu sources. Run sudo apt install php8.2 in your terminal to download and set up the specific release you need.

Legacy projects needing an older release allow installing an alternative PHP version on Ubuntu 24.04. Running `sudo apt install php8.2` installs PHP 8.2 directly. If your package list does not include the older version, add the Ondřej Surý PPA (Personal Package Archive, a repository containing extra software packages) to your system.

Advertisement

Install PHP version 8.2 on Ubuntu by executing the command below.

Advertisement

Default Ubuntu 24.04 repositories missing PHP 8.2 require adding a third-party PPA (Personal Package Archive) supplying that specific release.

Execute the command below to add the repository.

Advertisement

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

Advertisement

Refreshed package indexes allow attempting the PHP 8.2 installation again.

Check installed modules for PHP 8.2 by running `php -m`. Replacing `'version 8.3'` with `'8.2'` for each listed module confirms both PHP 8.2 and PHP 8.3 reside on the system.

Advertisement

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

Advertisement

Both [PHP 8.3] and [PHP 8.2] are now installed, though web servers like Apache or Nginx might still target PHP 8.3.

Switch PHP in Apache

Switching your active PHP version in Apache requires disabling the old module and enabling the new one so your web server loads the correct files. Run sudo a2dismod php8.3 to turn off the current version, then run sudo a2enmod php8.2 to activate your target version. Restart Apache afterward to apply the change.

Switching the active PHP version for Apache requires executing specific commands.

Disable the current PHP module.

🐧Bash / Shell
sudo a2dismod php8.3

Enable the preferred PHP version.

🐧Bash / Shell
sudo a2enmod php8.2

Restart Apache to apply the modifications.

Updating the Nginx configuration points the web server to the new PHP version after downgrading PHP on Ubuntu 24.04. Adjusting the `fastcgi_pass` setting inside the Nginx server block targets the socket file for the newly installed release, such as `unix:/var/run/php/php8.2-fpm.sock`.

🐘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 to save the configuration changes.

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

The process finishes here.

Conclusion:

Managing different PHP versions keeps applications stable. Review these key takeaways:

    • 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.

Handling PHP versions on Ubuntu 24.04 secures application reliability; for instance, reverting to PHP 8.1 resolves compatibility roadblocks when legacy code demands it.

Here is a short recap of the whole process:

  • Check Current PHP Version: Always start by verifying your existing PHP version.
  • List Installed PHP Modules: See which modules are installed so the older version has the same ones and your site stays compatible.
  • Install Older PHP Version: Install the version you need, such as PHP 8.2, using the commands from the steps above. This requires the Ondřej Surý PPA.
  • Verify PHP and Modules: Confirm that the older version and its required modules are installed correctly.
  • Configure Web Server: Switch the PHP version in Apache or Nginx, depending on which one you run.
  • Restart Services: Restart your web server and PHP-FPM after every configuration change. The new version is not used until you do.

If the site misbehaves on the older version, you can undo the change. Point Apache or Nginx back at PHP 8.3 and restart the services. Because both versions stay installed, nothing needs to be reinstalled.

Managing PHP versions this way keeps your applications reliable. For instance, reverting to PHP 8.1 clears up compatibility problems when legacy code demands it.

Switch PHP in Apache

Switching your active PHP version in Apache requires disabling the old module and enabling the new one so your web server loads the correct files. Run sudo a2dismod php8.3 to turn off the current version, then run sudo a2enmod php8.2 to activate your target version. Restart Apache afterward to apply the change.

Switching the active PHP version for Apache requires executing specific commands.

Disable the current PHP module.

🐧Bash / Shell
sudo a2dismod php8.3

Enable the preferred PHP version.

🐧Bash / Shell
sudo a2enmod php8.2

Restart Apache to apply the modifications.

Updating the Nginx configuration points the web server to the new PHP version after downgrading PHP on Ubuntu 24.04. Adjusting the `fastcgi_pass` setting inside the Nginx server block targets the socket file for the newly installed release, such as `unix:/var/run/php/php8.2-fpm.sock`.

🐘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 to save the configuration changes.

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

The process finishes here.

Conclusion:

Managing different PHP versions keeps applications stable. Review these key takeaways:

    • 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.

Handling PHP versions on Ubuntu 24.04 secures application reliability; for instance, reverting to PHP 8.1 resolves compatibility roadblocks when legacy code demands it.

Install older version of PHP

Installing an older PHP version on Ubuntu 24.04 lets you run legacy code that fails on newer releases. You can add the third-party software repository to get past versions if they are missing from the default Ubuntu sources. Run sudo apt install php8.2 in your terminal to download and set up the specific release you need.

Legacy projects needing an older release allow installing an alternative PHP version on Ubuntu 24.04. Running `sudo apt install php8.2` installs PHP 8.2 directly. If your package list does not include the older version, add the Ondřej Surý PPA (Personal Package Archive, a repository containing extra software packages) to your system.

Install PHP version 8.2 on Ubuntu by executing the command below.

Default Ubuntu 24.04 repositories missing PHP 8.2 require adding a third-party PPA (Personal Package Archive) supplying that specific release.

Execute the command below to add the repository.

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

Refreshed package indexes allow attempting the PHP 8.2 installation again.

Check installed modules for PHP 8.2 by running `php -m`. Replacing `'version 8.3'` with `'8.2'` for each listed module confirms both PHP 8.2 and PHP 8.3 reside on the system.

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

Both [PHP 8.3] and [PHP 8.2] are now installed, though web servers like Apache or Nginx might still target PHP 8.3.

Switch PHP in Apache

Switching your active PHP version in Apache requires disabling the old module and enabling the new one so your web server loads the correct files. Run sudo a2dismod php8.3 to turn off the current version, then run sudo a2enmod php8.2 to activate your target version. Restart Apache afterward to apply the change.

Switching the active PHP version for Apache requires executing specific commands.

Disable the current PHP module.

🐧Bash / Shell
sudo a2dismod php8.3

Enable the preferred PHP version.

🐧Bash / Shell
sudo a2enmod php8.2

Restart Apache to apply the modifications.

Updating the Nginx configuration points the web server to the new PHP version after downgrading PHP on Ubuntu 24.04. Adjusting the `fastcgi_pass` setting inside the Nginx server block targets the socket file for the newly installed release, such as `unix:/var/run/php/php8.2-fpm.sock`.

🐘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 to save the configuration changes.

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

The process finishes here.

Conclusion:

Managing different PHP versions keeps applications stable. Review these key takeaways:

    • 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.

Handling PHP versions on Ubuntu 24.04 secures application reliability; for instance, reverting to PHP 8.1 resolves compatibility roadblocks when legacy code demands it.

Downgrading PHP on Ubuntu 24.04 lets you run older websites that break on newer PHP releases. PHP is the server-side programming language behind WordPress and many other web applications.

⚡ 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.

Advertisement

Ubuntu 24.04 ships with PHP 8.3 by default, but older code often needs PHP 8.1 or 8.2. You don't have to remove 8.3 to do this. You install the older version alongside it with the terminal and the Ondřej Surý PPA, then point your web server at the version you want. That also makes the change easy to undo. Use an account with sudo rights, and back up your site and its configuration files before you start.

  1. Open a terminal and check your current PHP version with php -v. You should see a version string such as 8.3.x.
  2. List the installed PHP modules with dpkg --get-selections | grep -i php. Save this list, because modules are installed separately for each PHP version and you will need the same ones for the older release.
  3. Add the Ondřej Surý PPA by running sudo add-apt-repository ppa:ondrej/php. Ubuntu's default repositories carry only PHP 8.3 on 24.04, so you need this PPA for 8.1 or 8.2.
  4. Update your package list with sudo apt update. The PPA's packages should now appear as available.
  5. Install the older PHP version and its common modules. For example, to install PHP 8.2, use sudo apt install php8.2 php8.2-cli php8.2-common php8.2-opcache php8.2-readline php8.2-bcmath php8.2-curl. Add any extra modules from your saved list in the same way.
  6. Check that both versions are installed by running php -v and php8.2 -v (or the command for your chosen version). The command line may still report 8.3 as the default. That is normal, because the web server setting decides which version your sites use.
  7. If you use Apache, disable the current PHP module (for example sudo a2dismod php8.3) and enable the new one (for example sudo a2enmod php8.2). Then restart Apache.
  8. If you use Nginx, edit your server block's fastcgi_pass directive so it points to the new PHP-FPM socket (for example unix:/var/run/php/php8.2-fpm.sock). Then restart Nginx and PHP-FPM.

Get PHP details

Checking your current PHP version on Ubuntu 24.04 takes a few seconds. Run php -v to see the exact release installed on your system. This confirms your starting point before you downgrade PHP on Ubuntu 24.04 to an older release, and it is always the first step.

Run the command below to show the active PHP version.

🐘PHP
php --version
php -v

The output should look like the example below. In this case [8.3.6] is the installed version. Your number may differ slightly, but on a fresh Ubuntu 24.04 install it will be in the 8.3 series.

🐘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, check which PHP modules are installed. Older PHP versions don't inherit modules from 8.3. Each extension, such as MySQL or cURL support, has to be installed again for the new version. Note which ones your site actually uses.

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

The command lists the active PHP modules, with output similar to the text below.

Identifying the target PHP version and necessary modules prepares the system for the downgrade process. Matching project needs with a release like PHP 8.1 keeps applications running correctly on Ubuntu 24.04.

Here is a short recap of the whole process:

  • Check Current PHP Version: Always start by verifying your existing PHP version.
  • List Installed PHP Modules: See which modules are installed so the older version has the same ones and your site stays compatible.
  • Install Older PHP Version: Install the version you need, such as PHP 8.2, using the commands from the steps above. This requires the Ondřej Surý PPA.
  • Verify PHP and Modules: Confirm that the older version and its required modules are installed correctly.
  • Configure Web Server: Switch the PHP version in Apache or Nginx, depending on which one you run.
  • Restart Services: Restart your web server and PHP-FPM after every configuration change. The new version is not used until you do.

If the site misbehaves on the older version, you can undo the change. Point Apache or Nginx back at PHP 8.3 and restart the services. Because both versions stay installed, nothing needs to be reinstalled.

Managing PHP versions this way keeps your applications reliable. For instance, reverting to PHP 8.1 clears up compatibility problems when legacy code demands it.

Switch PHP in Apache

Switching your active PHP version in Apache requires disabling the old module and enabling the new one so your web server loads the correct files. Run sudo a2dismod php8.3 to turn off the current version, then run sudo a2enmod php8.2 to activate your target version. Restart Apache afterward to apply the change.

Switching the active PHP version for Apache requires executing specific commands.

Disable the current PHP module.

🐧Bash / Shell
sudo a2dismod php8.3

Enable the preferred PHP version.

🐧Bash / Shell
sudo a2enmod php8.2

Restart Apache to apply the modifications.

Updating the Nginx configuration points the web server to the new PHP version after downgrading PHP on Ubuntu 24.04. Adjusting the `fastcgi_pass` setting inside the Nginx server block targets the socket file for the newly installed release, such as `unix:/var/run/php/php8.2-fpm.sock`.

🐘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 to save the configuration changes.

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

The process finishes here.

Conclusion:

Managing different PHP versions keeps applications stable. Review these key takeaways:

    • 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.

Handling PHP versions on Ubuntu 24.04 secures application reliability; for instance, reverting to PHP 8.1 resolves compatibility roadblocks when legacy code demands it.

Install older version of PHP

Installing an older PHP version on Ubuntu 24.04 lets you run legacy code that fails on newer releases. You can add the third-party software repository to get past versions if they are missing from the default Ubuntu sources. Run sudo apt install php8.2 in your terminal to download and set up the specific release you need.

Legacy projects needing an older release allow installing an alternative PHP version on Ubuntu 24.04. Running `sudo apt install php8.2` installs PHP 8.2 directly. If your package list does not include the older version, add the Ondřej Surý PPA (Personal Package Archive, a repository containing extra software packages) to your system.

Install PHP version 8.2 on Ubuntu by executing the command below.

Default Ubuntu 24.04 repositories missing PHP 8.2 require adding a third-party PPA (Personal Package Archive) supplying that specific release.

Execute the command below to add the repository.

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

Refreshed package indexes allow attempting the PHP 8.2 installation again.

Check installed modules for PHP 8.2 by running `php -m`. Replacing `'version 8.3'` with `'8.2'` for each listed module confirms both PHP 8.2 and PHP 8.3 reside on the system.

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

Both [PHP 8.3] and [PHP 8.2] are now installed, though web servers like Apache or Nginx might still target PHP 8.3.

Switch PHP in Apache

Switching your active PHP version in Apache requires disabling the old module and enabling the new one so your web server loads the correct files. Run sudo a2dismod php8.3 to turn off the current version, then run sudo a2enmod php8.2 to activate your target version. Restart Apache afterward to apply the change.

Switching the active PHP version for Apache requires executing specific commands.

Disable the current PHP module.

🐧Bash / Shell
sudo a2dismod php8.3

Enable the preferred PHP version.

🐧Bash / Shell
sudo a2enmod php8.2

Restart Apache to apply the modifications.

Updating the Nginx configuration points the web server to the new PHP version after downgrading PHP on Ubuntu 24.04. Adjusting the `fastcgi_pass` setting inside the Nginx server block targets the socket file for the newly installed release, such as `unix:/var/run/php/php8.2-fpm.sock`.

🐘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 to save the configuration changes.

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

The process finishes here.

Conclusion:

Managing different PHP versions keeps applications stable. Review these key takeaways:

    • 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.

Handling PHP versions on Ubuntu 24.04 secures application reliability; for instance, reverting to PHP 8.1 resolves compatibility roadblocks when legacy code demands it.

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 *