The free web hosting control panel Virtualmin comes by default with PHP version 5.3, which is pretty old version released in 2009 and no longer in development. However, Virtualmin does not provide an easy way to upgrade PHP 5.3 to newer stable PHP versions such as PHP 5.4, PHP 5.5, PHP 5.6 or PHP 7.

Most PHP upgrading guides involve direct replacement and upgrading of PHP and modification of various Apache HTTPD web server and PHP INI configuration files to use the newly installed PHP version. However, messing directly with the core files are not a recommended way to upgrade PHP in Virtualmin as it may bring conflicts to Virtualmin and/or Webmin base in future.

If you must use a newer PHP version in Virtualmin environment, Virtualmin does support installation of multile PHP versions since Virtualmin 3.99. With more than one PHP versions installed, you can choose which version to use for a given domain (virtual server), or per-directory.

The following guide on installing the additional second PHP is based on 64-bit CentOS 6 or 7 by using the Software Collections (SCLs). Software Collections allows users to build and concurrently install multiple versions of the same software components on the system, without affecting the system versions of the default packages installed from system distribution. Software Collections repository installs the additional packages in /opt/ directory, while keeping the current packages untouched in /usr/ directory. Software Collections repository is available for major RPM-based Linux distributions, including Red Hat Enterprise Linux, Fedora, CentOS, and Scientific Linux. Thus, the guide should work on most of these Linux distros, but on 64-bit system only, as SCLs only provide x86_x64 packages.

How to Install PHP 5.4 or PHP 5.5 for Virtualmin from Software Collections Repository

  1. Login to the server as root via physical console or SSH.
  2. Install the Software Collections tools:
    yum install scl-utils
  3. Download the PHP RPM package with repository for your system.

    For PHP 5.4 on RHEL 6 and CentOS 6:

    wget https://www.softwarecollections.org/en/scls/rhscl/php54/epel-6-x86_64/download/rhscl-php54-epel-6-x86_64.noarch.rpm

    For PHP 5.4 on RHEL 7 and CentOS 7:

    wget https://www.softwarecollections.org/en/scls/rhscl/php54/epel-7-x86_64/download/rhscl-php54-epel-7-x86_64.noarch.rpm

    For PHP 5.5 on RHEL 6 and CentOS 6:

    wget https://www.softwarecollections.org/en/scls/rhscl/php55/epel-6-x86_64/download/rhscl-php55-epel-6-x86_64.noarch.rpm

    For PHP 5.5 on RHEL 7 and CentOS 7:

    wget https://www.softwarecollections.org/en/scls/rhscl/php55/epel-7-x86_64/download/rhscl-php55-epel-7-x86_64.noarch.rpm
  4. Install the PHP repo package.

    For PHP 5.4:

    yum install rhscl-php54-*.noarch.rpm

    For PHP 5.5:

    yum install rhscl-php55-*.noarch.rpm
  5. Install the additional PHP:

    For PHP 5.4:

    yum install php54

    For PHP 5.5:

    yum install php55
  6. Start using Software Collections with new bash instance with additional PHP enabled.

    For PHP 5.4:

    scl enable php54 bash

    For PHP 5.5:

    scl enable php55 bash
Note
If you’re using CentOS, you can also install CentOS Software Collections release configs repository, centos-release-SCL, with yum. Then directly proceed to install php54 or php55 with yum.

Configure Virtual Server (Website or Domain) to Use Another PHP Version in Virtualmin

  1. Login to Virtualmin, and verify that Virtualmin does see multiple versions of PHP installed by selecting System Settings -> Re-Check Configuration. One the line should resemble the following:

    The following PHP versions are available : 5.3.3 (/usr/bin/php-cgi), 5.5.6 (/opt/rh/php55/root/usr/bin/php-cgi)

    Virtualmin Re-Check PHP Configs

  2. Optional: By default, Virtualmin will automatically use the highest version of PHP available for new Virtual Servers. If you want to specify which version of PHP to use, go to System Settings -> Server Templates -> Default Settings -> Apache Website, and change the value for Default PHP version option.
  3. To change an existing Virtual Server to use another PHP version, select the Virtual Server from the drop-down list, then go to Server Configuration -> PHP Versions.

    Specify the default PHP version to be used for the Virtual Server by select the desired version as the value for Default HTML directory from the drop-down list.

    Assign Another PHP Version for Virtual Server

    If required, enter the website sub-directory and specify a different PHP version to be used for that specific directory.

Note
Before actually using the newly installed PHP version, you may want to install the required PHP extensions or dynamic shared objects that add support for various libraries or protocols to PHP. Some example includes php54-php-cli (php55-php-cli), php54-php-mysql (php55-php-mysql), php54-php-gd (php55-php-gd), php54-php-imap (php55-php-imap), php54-php-mbstring (php55-php-mbstring) and etc.

Note that some popular PHP extensions require additional SCL repository. For example, php54-php-mcrypt (php55-php-mcrypt) and php54-php-mysqlnd (php55-php-mysqlnd). To install these packages, download and install the Remi Collect’s Php54more or Php55more repo package, which extends the PHP collection available in RHSCL or CentsOS-SCL, according to the PHP and distro version.

For PHP 5.4 on RHEL 6 and CentOS 6:

wget https://www.softwarecollections.org/en/scls/remi/php54more/epel-6-x86_64/download/remi-php54more-epel-6-x86_64.noarch.rpm

For PHP 5.4 on RHEL 7 and CentOS 7:

wget https://www.softwarecollections.org/en/scls/remi/php54more/epel-7-x86_64/download/remi-php54more-epel-7-x86_64.noarch.rpm

For PHP 5.5 on RHEL 6 and CentOS 6:

wget https://www.softwarecollections.org/en/scls/remi/php55more/epel-6-x86_64/download/remi-php55more-epel-6-x86_64.noarch.rpm

For PHP 5.5 on RHEL 7 and CentOS 7:

wget https://www.softwarecollections.org/en/scls/remi/php55more/epel-7-x86_64/download/remi-php55more-epel-7-x86_64.noarch.rpm