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
- Login to the server as root via physical console or SSH.
- Install the Software Collections tools:
yum install scl-utils
- 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
- 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
- Install the additional PHP:
For PHP 5.4:
yum install php54
For PHP 5.5:
yum install php55
- 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
Configure Virtual Server (Website or Domain) to Use Another PHP Version in Virtualmin
- 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)
- 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.
- 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.
If required, enter the website sub-directory and specify a different PHP version to be used for that specific directory.
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