Category: Virtualmin

Multiple PHP Versions on Virtualmin

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)](#toc-installing-php-72-on-centos-6-and-7-yTjimn_w “CentOS (6 and above)”) using the CentOS Software Collections repository, or on [Debian 10](#toc-installing-php-56-70-71-72-73-on-debian-10-buster-EkAj9qSJ “Debian 10”) using a PPA, or on [Ubuntu 14.04](#toc-configuring-the-second-php-version-in-virtualmin-ooq1ksVU “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,opcache}

Installing PHP 7.4 and/or 8.0 on CentOS 7

Install Remi Release repo and clear cache

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

Install PHP packages version 7.4 and/or 8.0

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

Installing PHP 7.3, 7.4 and/or 8.0 on CentOS 8

Install Remi Release repo and clear cache

dnf -y install https://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,opcache}
dnf -y install php74-php-{cli,pdo,fpm,zip,gd,xml,mysqlnd,opcache}
dnf -y install php80-php-{cli,pdo,fpm,zip,gd,xml,mysqlnd,opcache}

Installing PHP 5.6 and/or 7.4 and/or 8.0 on Debian 9/10

Enable the deb.sury.org 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/php.list'

Update all repositories

apt update

Install PHP packages version 5.6 and/or 7.4 and/or 8.0

apt-get install php5.6-{cli,pdo,fpm,zip,gd,xml,mysql,cgi}
apt-get install php7.4-{cli,pdo,fpm,zip,gd,xml,mysql,cgi}
apt-get install php8.0-{cli,pdo,fpm,zip,gd,xml,mysql,cgi}

Installing PHP version 5.6 and/or 7.3 and/or 8.0 on Ubuntu 18.04 and 20.04

Install the PPA

add-apt-repository ppa:ondrej/php && apt-get update

Install the PHP packages

apt-get install php5.6-{cli,pdo,fpm,zip,gd,xml,mysql,cgi}
apt-get install php7.3-{cli,pdo,fpm,zip,gd,xml,mysql,cgi}
apt-get install php8.0-{cli,pdo,fpm,zip,gd,xml,mysql,cgi}

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 Options.

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.