Virtualmin allows the selection of different PHP versions and execution modes for each domain. The recommended execution mode is FPM, but CGI/FCGId is also available, enabling per-directory PHP version settings.

Installing additional PHP versions

On RHEL, Alma, Rocky, Oracle, CentOS Stream and Fedora Linux

  1. Install Remi repository
    . /etc/os-release && repo_dir=$([ "$ID" = "fedora" ] && echo "fedora" || echo "enterprise") && sudo dnf -y install "https://rpms.remirepo.net/$repo_dir/remi-release-$(rpm -E %$ID).rpm" && sudo dnf clean all
    
  2. Install PHP packages
    sudo dnf install php81-php-{cli,fpm,pdo,gd,mbstring,mysqlnd,opcache,curl,xml,zip}
    
    • Replace php81 with the desired PHP version, e.g., php83.
    • Check available PHP versions and extensions in the Remi Repository or use dnf search php.

On Debian and Ubuntu

The Sury PHP repository provides additional PHP versions for Debian and Ubuntu. Ubuntu support covers LTS releases during their standard support period.

If your system uses the old ppa:ondrej/php repository, follow the migration instructions below. If it already uses packages.sury.org/php without the old PPA, skip to installing PHP packages. Otherwise, enable the repository as follows.

  1. Enable the Sury PHP repository

    These commands follow the upstream setup instructions:

    sudo apt-get update
    sudo apt-get -y install lsb-release ca-certificates curl
    sudo curl -fsSLo /tmp/debsuryorg-archive-keyring.deb https://packages.sury.org/debsuryorg-archive-keyring.deb
    sudo dpkg -i /tmp/debsuryorg-archive-keyring.deb
    sudo sh -c 'echo "deb [signed-by=/usr/share/keyrings/debsuryorg-archive-keyring.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
    sudo apt-get update
    
  2. Install PHP packages

    sudo apt-get install php8.3-{cgi,cli,fpm,pdo,gd,mbstring,mysqlnd,opcache,curl,xml,zip}
    

    Replace php8.3 with the desired version. Check available versions and extensions with apt-cache search --names-only '^php'.

Migrating from the Ubuntu PHP PPA

The Ondrej PHP PPA is frozen and no longer receives updates, including security fixes. The replacement is packages.sury.org/php.

If the Sury repository is already enabled for your Ubuntu release, remove the old PPA with sudo add-apt-repository --remove ppa:ondrej/php, then run sudo apt update and check the repository. Otherwise, follow the instructions for your Ubuntu version below.

Ubuntu 26.04

Use the Sury repository setup instructions above. The debsuryorg-repository-php migration package used for older Ubuntu releases is not available from the Ubuntu 26.04 PPA.

If you already added the old PPA, remove it first:

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

Then enable the Sury repository and install the PHP packages. Removing the PPA does not uninstall PHP.

Ubuntu 22.04 and 24.04

If the old PPA is enabled, run these commands one at a time. Only remove the PPA after debsuryorg-repository-php installs successfully. That package enables the replacement repository.

If the first command asks you to accept the PPA’s label change to PPA for PHP (deprecated), accept it. If it stops with a label-change error, run sudo apt update --allow-releaseinfo-change-label, then continue with the package installation.

sudo apt update
sudo apt install debsuryorg-repository-php
sudo add-apt-repository --remove ppa:ondrej/php
sudo apt update

This migration keeps your installed PHP packages, configuration and Virtualmin’s per-domain PHP selections. Future package updates come from the new repository.

Check the new repository

Run apt-cache policy php8.3-fpm, replacing 8.3 with each installed PHP version. The version table should include packages.sury.org/php and no PHP PPA entries.

An installed PPA build may still be the candidate until Sury publishes a package with a higher version. This does not mean the migration failed.

If the PHP PPA still appears, check /etc/apt/sources.list and the .list and .sources files in /etc/apt/sources.list.d/. Disable any remaining PHP PPA entries, then run sudo apt update again. Manually added entries may remain after add-apt-repository --remove.

If you use APT pinning or custom unattended-upgrades rules, update any rules tied to the old PPA’s origin. These rules do not automatically follow the repository change.

Installing additional PHP extensions

In order to add additional PHP extensions, for all PHP versions installed on the system, use the following command:

Debian and derivatives

for php in $(ls /etc/php); do sudo apt-get install -y "php$php-"{curl,intl}; done

EL systems

for php in $(scl list-collections 2>/dev/null | grep 'php' | sed 's/$/-php/') php; do for ext in curl intl; do sudo dnf -y install "${php}-${ext}"; done; done

A command above will install the curl and intl extensions for all PHP versions installed on the system. You can replace the names of the extensions with the ones you need to have installed.

Configuring default PHP version

After installing another PHP version:

  1. Verify in Virtualmin: Log in, go to System Settings ⇾ Re-Check Configuration. Among other information, you should see available PHP versions and execution modes.

  2. Set default PHP version: Configure the default version for new virtual servers in System Settings ⇾ Server Templates ⇾ PHP Options page. For specific virtual server, set the PHP version in Web Configuration ⇾ PHP Options page.