Multiple PHP Versions

Introduction

If you have multiple PHP versions installed, Virtualmin allows you to choose which version to use for a given domain, or even per-directory.

While this feature can work with any Linux distribution, it works best with 64 bit CentOS (6 and above) using the CentOS Software Collections repository, or on Debian 10 using a PPA, or on Ubuntu 14.04 using a PPA.

Installing PHP 7.3 on CentOS 6 and 7

Notes about CentOS

  • CentOS has a special repository called "Software Collections", which is a system for installing multiple software versions on one server. Using packages provided by in the Software Collections repository, it's possible to install more recent PHP versions /opt/, while keeping the default PHP version installed in /usr/.

  • The repository providing these packages currently only provides 64 bit packages. If you are using 32 bit CentOS, there are unfortunately no PHP packages for that.

Install the SCL Repo:
yum -y install centos-release-scl
Install the PHP packages:
yum -y install rh-php73-php-{cli,pdo,fpm,zip,gd,xml,mysqlnd}

Lastly, see the information on configuring the second PHP version below.

Installing PHP 7.4 on CentOS 7

Install Remi Release repo and clear cache:

yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm && yum clean all

Install PHP packages version 7.4:

yum -y install php74-php-{cli,pdo,fpm,zip,gd,xml,mysqlnd}

Installing PHP 7.3 and 7.4 on CentOS 8

Install Remi Release repo and clear cache:

dnf -y install http://rpms.remirepo.net/enterprise/remi-release-8.rpm && dnf clean all

Install PHP packages version 7.3 and/or 7.4:

dnf -y install php73-php-{cli,pdo,fpm,zip,gd,xml,mysqlnd}
dnf -y install php74-php-{cli,pdo,fpm,zip,gd,xml,mysqlnd}

Installing PHP 5.6, 7.0, 7.1, 7.2, 7.3 on Debian 10 Buster

Enable the DEB.SURY.ORG repository:
sudo LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php
Update all repositories:
sudo apt update
Install PHP packages version 5.6, 7.0, 7.1, 7.2, 7.3:
sudo apt-get install php5.6 php5.6-cgi php5.6-cli php5.6-fpm php5.6-mysql php7.0 php7.0-cgi php7.0-cli php7.0-fpm php7.0-mysql php7.1 php7.1-cgi php7.1-cli php7.1-fpm php7.1-mysql php7.2 php7.2-cgi php7.2-cli php7.2-fpm php7.2-mysql php7.3 php7.3-cgi php7.3-cli php7.3-fpm php7.3-mysql

Lastly, see the information on configuring the second PHP version below.

Installing PHP 7.3 on Ubuntu 16.04 and 18.04

Install the PPA:
add-apt-repository ppa:ondrej/php && apt-get update
Install the PHP packages:
apt-get install php7.3 php7.3-mysql php7.3-cgi php7.3-cli php7.3-fpm

Lastly, see the information on configuring the second PHP version below.

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 versions are available : 5.3.3 (/usr/bin/php-cgi), 5.6.25 (/opt/rh/rh-php56/root/usr/bin/php-cgi), 7.0.10 (/opt/rh/rh-php70/root/usr/bin/php-cgi)

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, and on that screen you can set the default PHP version to use in the field Default PHP version.

Configuring Individual Virtual Servers

You can configure the PHP version being used for a specific Virtual Server by selecting Server Configuration -> PHP Versions.

The first line there specifies what PHP version will be used by default.

If you wish, you can specify a different PHP version to be used for a specific directory.

Smiley face