Skip to main content
To install multiple PHP versions on Ubuntu, add the ppa:ondrej/php repository (on Debian, packages.sury.org), then install each version’s FPM package, for example sudo apt install php8.3-fpm php8.4-fpm. Each version runs as its own service with its own socket, such as /run/php/php8.4-fpm.sock. Point each site’s fastcgi_pass (Nginx) or SetHandler (Apache) at the socket for the version it needs.

Before you start

  • Use a user with sudo. If you are root, leave out sudo.
  • Take a backup or snapshot first. Adding a repository can upgrade the PHP version you already run.
  • Supported PHP branches today: 8.2 and 8.3 get security fixes only (until 31 December 2026 and 31 December 2027), 8.4 and 8.5 get full support. Avoid 8.1 and older; they are end-of-life upstream.
Each Ubuntu and Debian release ships one PHP version: 8.3 on Ubuntu 24.04, 8.4 on Debian 13. For other versions, the usual source is the repository run by Ondřej Surý, who maintains PHP packages for Debian. It is a third-party repository, not part of Ubuntu or Debian.

How to add the PHP repository

The PPA supports Ubuntu LTS releases in standard support (22.04 and 24.04).

How to install a second PHP version

Install the FPM package and the extensions your app needs, with the version in each name:
Repeat with php8.3-…, php8.5-… and so on. Each version gets its own files: Check that both services run:

How to choose the PHP version per site

In each site’s server block, set the socket for the version that site needs:

How to change the default PHP for the command line

The php command (used by Composer, cron jobs and WP-CLI) follows the Debian alternatives system:
Pick a number from the list, or set it directly:
You can also call a version by name, for example php8.3 artisan migrate.

How to check it worked

Put a test file in the site’s web root:
The output shows the version and fpm-fcgi, for example 8.4.x fpm-fcgi.

How to run several PHP versions on AlmaLinux and Rocky

Use Remi’s repository, which installs extra versions as prefixed packages next to the system PHP:
On release 9, use epel-release-latest-9 and remi-release-9. The PHP 8.5 FPM socket is /var/opt/remi/php85/run/php-fpm/www.sock and its configuration lives under /etc/opt/remi/php85. Use that socket in fastcgi_pass.

Frequently asked questions

Will adding the repository upgrade my current PHP?

It can upgrade the patch level and extensions of the version you already have. It does not switch your sites to a new major version; you choose that per site.

Which extensions do I need for each version?

Extensions are per version. If a site needs mbstring on PHP 8.4, install php8.4-mbstring even if php8.3-mbstring is already there. List loaded modules with php8.4 -m.

How do I remove an old PHP version?

Switch every site away from it first, then run sudo apt purge 'php8.2*' and sudo apt autoremove.

Do php.ini changes apply to all versions?

No. Each version has its own php.ini and FPM pool. See increase PHP upload size.

VPS and dedicated server guides

Every server guide in one place.

Install a LEMP stack

Nginx with PHP-FPM.

Install a LAMP stack

Apache with PHP.

Fix 502 Bad Gateway

Wrong socket name? Start here.

Update Linux packages

Keep every version patched.

Checked against the official PHP supported versions page, the deb.sury.org FAQ and Remi’s PHP 8.5 guides on 4 November 2026; Nginx and Apache per-site PHP-FPM configuration and update-alternatives tested on Ubuntu 24.04 LTS with PHP 8.3. Adding the third-party repositories was not tested. Commands can differ on other distributions or releases.

Need Extra Help?

If you encounter any issues, our support team is ready to assist:

Save on Your Hosting

Ready to upgrade your hosting? Use code KB20 at checkout for 20% off your first order!

Last Updated: November 2026