Skip to content
Follow
Ubuntu Linux

How to Downgrade PHP Version on Ubuntu 24.04

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

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

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

Ubuntu 24.04 ships with PHP 8.3 by default, but older code often needs PHP 8.1 or 8.2 to work right. You can safely install an older PHP version alongside your current setup using the terminal and the Ondřej Surý PPA repository.

  1. First, open your terminal and check your current PHP version by typing php -v.
  2. Next, list all installed PHP modules with dpkg --get-selections | grep -i php to see what you have.
  3. If the older PHP version you need isn’t in Ubuntu’s default list, add the Ondřej Surý PPA by running sudo add-apt-repository ppa:ondrej/php.
  4. Update your package list with sudo apt update.
  5. Install the specific 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.
  6. Verify both versions are installed by checking php -v and php8.2 -v (or your chosen version).
  7. For Apache, disable the current PHP module (e.g., sudo a2dismod php8.3) and enable the new one (e.g., sudo a2enmod php8.2), then restart Apache.
  8. For Nginx, update your server block’s fastcgi_pass to point to the new PHP-FPM socket (e.g., unix:/var/run/php/php8.2-fpm.sock) and restart Nginx and PHP-FPM.

Get PHP details

Checking the current PHP version forms the first step when handling a downgrade on Ubuntu 24.04. Opening the terminal and typing `php -v` reveals the exact version running on the system.

List the active version of PHP by running the command below.

🐘PHP
php --version
php -v

The executed command produces output matching the example below, showing [8.3.6] as the currently installed version.

🐘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

Run the command below to check which PHP modules remain installed.

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

The command outputs details matching the text below, displaying active PHP modules.

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.

Install older version of PHP

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. Software sources not containing the required release mean adding a third-party PPA (Personal Package Archive, an external software repository) becomes necessary.

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-commom php8.2-opcache php8.2-readline php8.2-bcmath php8.3-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 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.

How to downgrade PHP version in Ubuntu?

Opening the terminal reveals the active PHP version installed on the system, which defaults to 8.3.

What is the default PHP version for Ubuntu 24?

What PHP version does Ubuntu 24.04 include? Ubuntu 24.04 ships with PHP 8.3 in its default repositories.

How do I remove a specific version of PHP in Ubuntu?

Executing `sudo apt remove 'php8.0*'` removes PHP and associated packages for that release, reverting the system to an older installed version.

How do I change PHP version in Linux?

Switching the default PHP version relies on 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?

📬 Get new Windows tips in your inbox
One email when we publish something worth your time. No spam, unsubscribe anytime.
Tags: #Ubuntu Linux
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.

2845 articles → Twitter

📚 Related Tutorials

How to Install PHP on Ubuntu Linux
Ubuntu Linux How to Install PHP on Ubuntu Linux
How to Install Apache on Ubuntu Linux
Ubuntu Linux How to Install Apache on Ubuntu Linux
How to Install Nginx on Ubuntu Linux
Ubuntu Linux How to Install Nginx on Ubuntu Linux
Setup SSH Key Authentication on Ubuntu
Ubuntu Linux Setup SSH Key Authentication on Ubuntu

1 Comment

Leave a Comment

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