Multiple PHP Versions

[toc]

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.

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.4 on CentOS 6

  • Install the SCL Utils:

yum install scl-utils

  • Install repository package

rpm -Uvh https://www.softwarecollections.org/repos/rhscl/php54/epel-6-x86_64/noarch/rhscl-php54-epel-6-x86_64-1-2.noarch.rpm

  • Install the PHP packages

yum install php54 php54-php-mysqlnd

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

Installing PHP 5.5 on CentOS 6

  • Install the SCL Utils:

yum install scl-utils

  • Install repository package

rpm -Uvh https://www.softwarecollections.org/repos/rhscl/php55/epel-6-x86_64/noarch/rhscl-php55-epel-6-x86_64-1-2.noarch.rpm

  • Install the PHP packages

yum install php55 php55-php-mysqlnd

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

Installing PHP 5.5 on CentOS 7

  • Install the SCL Utils:

yum install scl-utils

  • Install repository package

rpm -Uvh https://www.softwarecollections.org/repos/rhscl/php55/epel-7-x86_64/noarch/rhscl-php55-epel-7-x86_64-1-2.noarch.rpm

  • Install the PHP packages

yum install php55 php55-php-mysqlnd

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

Installing PHP 5.6 on CentOS 7

  • Install the SCL Utils:

yum install scl-utils

  • Install repository package

rpm -Uvh https://www.softwarecollections.org/en/scls/rhscl/rh-php56/epel-7-x86_64/download/rhscl-rh-php56-epel-7-x86_64.noarch.rpm

  • Install the PHP packages

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

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.x (/opt/rh/php56/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 -> Apache Website, 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.

Old Way of Installing PHP 5.4 on CentOS 5.6 (deprecated, we recommend the above methods if possible)

To install PHP 5.4 from the Software Collections repository, perform the following steps:

  1. Log into your server over SSH as root
  2. Setup the SCL repository with this command: yum install centos-release-SCL
  3. Install PHP 5.4 and scl-utils with this command: yum install php54 php54-php-cli php54-php-mysql php54-php-gd