Multiple PHP Versions on One Server: PHP 7.4, 8.1, 8.2 Simultaneously

PHP · 19.04.2026
Multiple PHP Versions on One Server: PHP 7.4, 8.1, 8.2 Simultaneously

Why Multiple PHP Versions

Multi-site servers often need different PHP versions: one WordPress site requires PHP 8.1+, while a legacy Magento 1 only runs on PHP 7.4. The ondrej/php PPA supports all versions simultaneously.

Add ondrej/php Repository

sudo add-apt-repository ppa:ondrej/php
sudo apt update

Install Multiple Versions

sudo apt install php7.4-fpm php7.4-cli php7.4-mysql php7.4-mbstring
sudo apt install php8.1-fpm php8.1-cli php8.1-mysql php8.1-mbstring
sudo apt install php8.2-fpm php8.2-cli php8.2-mysql php8.2-mbstring

Nginx: Different PHP per Site

# New site — PHP 8.2
fastcgi_pass unix:/run/php/php8.2-fpm.sock;

# Legacy site — PHP 7.4
fastcgi_pass unix:/run/php/php7.4-fpm.sock;

Set Default PHP CLI Version

sudo update-alternatives --config php
Each PHP-FPM version runs independently with its own pools and php.ini. Changes to PHP 8.2 config do not affect PHP 7.4.
← Back to Knowledge Base Ask Support