How to install multiple PHP versions on the same server - Rocketeers app

  [ Rocketeers ](/)   

[Login](https://rocketeersapp.com/login) 

 On this page

 Knowledge
---------

How to install multiple PHP versions on the same server
=======================================================

### [\#PHP](https://rocketeersapp.com/knowledge/php)

One server, several sites, different PHP versions. Here is how to install PHP 8.2, 8.3, and 8.4 side by side and point each site at the version it needs.

 Published by [Mark van Eijk](https://rocketeersapp.com/author/mark-van-eijk) on June 30, 2026 · 2 minute read

1. [Install the versions you need](#content-install-the-versions-you-need)
2. [Point each site at a version](#content-point-each-site-at-a-version)
3. [Set the CLI default](#content-set-the-cli-default)
4. [Turn off the ones you don't use](#content-turn-off-the-ones-you-dont-use)
5. [Let Rocketeers handle it](#content-let-rocketeers-handle-it)

Not every site upgrades on the same schedule. One app needs PHP 8.4, an older one is stuck on 8.2, and they both live on the same server. The good news: PHP-FPM runs a separate service and socket per version, so you can install as many as you like and route each site to the right one.

[\#](#content-install-the-versions-you-need "Permalink")Install the versions you need
-------------------------------------------------------------------------------------

With the [ondrej/php PPA](/how-to-install-php) added, install each version's FPM and CLI packages. Just repeat the install for every version:

 ```
sudo add-apt-repository ppa:ondrej/php -y
sudo apt-get update

DEBIAN_FRONTEND=noninteractive sudo apt-get install -y \
  php8.2-fpm php8.2-cli php8.2-mysql php8.2-mbstring php8.2-xml php8.2-curl \
  php8.3-fpm php8.3-cli php8.3-mysql php8.3-mbstring php8.3-xml php8.3-curl \
  php8.4-fpm php8.4-cli php8.4-mysql php8.4-mbstring php8.4-xml php8.4-curl

```

Each version installs its own FPM service and its own socket:

 ```
sudo systemctl status php8.2-fpm php8.3-fpm php8.4-fpm

```

 ```
/var/run/php/php8.2-fpm.sock
/var/run/php/php8.3-fpm.sock
/var/run/php/php8.4-fpm.sock

```

[\#](#content-point-each-site-at-a-version "Permalink")Point each site at a version
-----------------------------------------------------------------------------------

This is the key step: in each site's [Nginx server block](/how-to-install-nginx), set `fastcgi_pass` to the socket of the version that site should use.

A site on PHP 8.4:

 ```
location ~ \.php$ {
    include fastcgi_params;
    fastcgi_pass unix:/var/run/php/php8.4-fpm.sock;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}

```

A different site on PHP 8.2 — same block, different socket:

 ```
    fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;

```

Reload Nginx after editing, and each site runs on its own version simultaneously:

 ```
sudo nginx -t && sudo service nginx reload

```

[\#](#content-set-the-cli-default "Permalink")Set the CLI default
-----------------------------------------------------------------

The command line `php` is separate from what your sites use over FPM. Pick which version `php` resolves to on the command line with `update-alternatives`:

 ```
sudo update-alternatives --set php /usr/bin/php8.4

```

Check it:

 ```
php -v

```

You can still call any version explicitly — `php8.2 artisan migrate`, `php8.3 -v` — regardless of the default.

[\#](#content-turn-off-the-ones-you-dont-use "Permalink")Turn off the ones you don't use
----------------------------------------------------------------------------------------

Every running FPM pool holds memory. If a version is installed but no site uses it, stop and disable its service so it isn't sitting idle — see [disabling unused PHP-FPM pools](/disable-unnecessary-and-unused-php-versions-php-fpm-pools).

Developing locally on a Mac? [Laravel Valet can switch PHP versions](/different-php-versions-laravel-valet) the same way for your local sites.

[\#](#content-let-rocketeers-handle-it "Permalink")Let Rocketeers handle it
---------------------------------------------------------------------------

Installing versions, remembering which socket maps to which site, keeping the CLI default straight, and shutting down idle pools is exactly the kind of bookkeeping that drifts out of sync over time. Rocketeers installs every PHP version you need on a server and lets each site choose its version with a click — the FPM socket wiring and the cleanup happen for you.

### Subscribe to our newsletter

Do you want to receive regular updates with fresh and exclusive content to learn more about web development, hosting, security and performance? Subscribe now!

  Fill in your email address to receive updates  Subscribe 

#### More in [\#PHP](https://rocketeersapp.com/knowledge/php)

- [How to run PHP files](https://rocketeersapp.com/knowledge/run-php-files)
- [PHP file upload exceeds upload\_max\_filesize](https://rocketeersapp.com/knowledge/php-file-upload-exceeds-upload-max-filesize)
- [PHP Warning: Undefined array key](https://rocketeersapp.com/knowledge/undefined-array-key-php)
- [PHP Fatal error: Allowed memory size exhausted](https://rocketeersapp.com/knowledge/php-allowed-memory-size-exhausted)
- [PHP: Call to a member function on null](https://rocketeersapp.com/knowledge/call-to-a-member-function-on-null)
- [PHP Fatal error: Class "X" not found](https://rocketeersapp.com/knowledge/php-class-not-found)

 [View all 11 articles →](https://rocketeersapp.com/knowledge/php)
