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 Ubuntu 14.04 using a PPA.

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

Note that 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.

Installing PHP 5.6 on CentOS 6 and 7

Install the SCL Repo:

yum install centos-release-scl

Install the PHP packages

yum install rh-php56 rh-php56-php-mysqlnd

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

Installing PHP 7 on CentOS 6 and 7

Install the SCL Repo:

yum install centos-release-scl

Install the PHP packages

yum install rh-php70 rh-php70-php-mysqlnd

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

Installing PHP 7 on Ubuntu 14.04

Install the PPA:

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

Install the PHP packages

apt-get install php7.0 php7.0-mysql php7.0-cgi php7.0-cli

Reset the default PHP back to PHP5 (optional)

update-alternatives --set php /usr/bin/php5

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.