Multiple PHP Versions

Introduction

If you have multiple PHP versions installed, Virtualmin allows you to choose execution mode and PHP version used for a given domain. Available execution modes are FPM (recommended) and CGI/FCGId. Latter mode enables to set different PHP versions on per-directory basis.

Installing on Alma, Rocky, CentOS Stream, Fedora Linux

Install Remi repository and clear cache

. /etc/os-release && dnf -y install https://rpms.remirepo.net/enterprise/remi-release-$(rpm -E %$ID).rpm && dnf clean all

Install additional PHP packages

dnf install php*-php-{cli,fpm,pdo,gd,mbstring,mysqlnd,opcache,xml,zip}

Note: php* should be replaced with a specific PHP version, i.e. php74, unless you really need to install all available additional PHP versions.

Installing on Debian

Enable sury/php repository

apt-get -y install apt-transport-https lsb-release ca-certificates curl && curl -sSL -o /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg && sh -c 'echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/sury-debian-php-$(lsb_release -sc).list' && apt-get update

Install additional PHP packages

apt-get install php*-{cgi,cli,fpm,pdo,gd,mbstring,mysqlnd,opcache,xml,zip}

Note: php* should be replaced with a specific PHP version, i.e. php7.4, unless you really need to install all available additional PHP versions.

Installing on Ubuntu

Enable ondrej/php repository

LC_ALL=C.UTF-8 add-apt-repository -y ppa:ondrej/php && apt-get update

Install additional PHP packages

apt-get install php*-{cgi,cli,fpm,pdo,gd,mbstring,mysqlnd,opcache,xml,zip}

Note: php* should be replaced with a specific PHP version, i.e. php7.4, unless you really need to install all available additional PHP versions.

Configuring the second PHP Version in Virtualmin 

Once you have completed the installation of a second PHP version on your server, you can verify that Virtualmin sees it by logging into Virtualmin, and clicking System Settings → Re-Check Config. You should see something like this:

The following PHP execution modes are available : fpm
The following PHP-FPM versions are available : 8.0.13 (php-fpm) 7.4.30 (php74-php-fpm) 8.2.0 (php82-php-fpm)

You can configure which one is the default PHP version used on new Virtual Servers. The default is to use the newest available. You can change that default in System Settings → Server Templates → Default → PHP Options page.

Configuring Individual Virtual Servers

You can configure the PHP version being used for a specific Virtual Server by selecting Server Configuration → PHP Options.