Running multiple PHP versions on CentOS 7 using Virtualmin

This guide will show how to install additional PHP version (in this tutorial we will install PHP version 5.6. Check my post here for PHP 7.0) on CentOS 7 by using the Software Collections and have Virtualmin detect and use it. What requires me to perform this is because I need to install Drupal 8 which requires PHP version 5.5.9 or higher but as of this writing CentOS 7 only provides PHP version 5.4.16 plus I don't want to affect the system version of the default PHP package installed from system distribution. Another is that the PHP version 5.6 still don't have extensions like jsmin, mcrypt, imap, pdo_odbc, pdo_pgsql, uploadprogress which my existing applications/sites uses them so I really need to keep the PHP version 5.4.

The Software Collections allows us to build and concurrently install multiple versions of the same software components on our system. It installs the additional packages in /opt/ directory while keeping the current packages untouched in /usr/ directory. Virtualmin supports installation of multile PHP versions since Virtualmin 3.99. It allows us choose which version to use for a given domain (virtual server) or per-directory.

Here are the steps:

  1. Login as root to your server's console terminal.

  2. Install the Software Collections utilities:

          
    yum install scl-utils
          
        
  3. Install the PHP version 5.6 RPM repository package for CentOS 7:

          
    rpm -Uvh https://vault.centos.org/7.4.1708/sclo/x86_64/rh/rh-php56/rh-php56-2.3-1.el7.x86_64.rpm
          
        
  4. Install the PHP package:

          
    yum install rh-php56
          
        
  5. (Optional) To start using Software Collections with new bash instance with PHP version 5.6:

          
    scl enable rh-php56 bash
          
        

    To verify it:

          
    php -v
          
        

    You should see the PHP version 5.6 instead of system's default version.

The log file can be found at /var/opt/rh/rh-php56/log/php-fpm/error.log.

Setup Apache to use the PHP 5.6 version for Virtualmin users:

  1. Virtualmin can't detect the default path /opt/rh/rh-php56/ created by the installation as it parse directory by /opt/rh/php*. As solution, lets create a symbolic link in able Virtualmin detect our newly installed PHP 5.6:

          
    ln -s /opt/rh/rh-php56/ /opt/rh/php56
          
        
  2. Login to your Virtualmin and go to System Settings -> Re-Check Configuration. You should see one of the line look something like this:

          
    The following PHP versions are available : 5.4.16 (/bin/php-cgi), 5.6.5 (/opt/rh/php56/root/usr/bin/php-cgi)
          
        
  3. Now lets change an existing virtual server to use the PHP version 5.6.5. Select a virtual server that needs PHP version 5.6.5 from the dropdown menu, go to Server Configuration -> PHP Versions and click the "Save Versions" button:

    Virtualmin multiple PHP version selection

  4. To install extension modules (like MySQL driver, Opcache, etc.) for our new PHP version 5.6.5, please read this article: Install extension modules for PHP 5.6 created under Software Collections (multiple PHP versions in a system)

Setup Apache to use the PHP 5.6 version for non-Virtualmin users:

Install APache plugin mod_fcgid:

  
yum install mod_fcgid
  

Create FCGI wrapper script:

  
vi /home/drupal/fcgi-bin/php5.6.fcgi
  
  
#!/bin/bash
PHPRC=/etc/opt/rh/rh-php56
export PHPRC
umask 022
export PHP_FCGI_CHILDREN
PHP_FCGI_MAX_REQUESTS=100000
export PHP_FCGI_MAX_REQUESTS
SCRIPT_FILENAME=$PATH_TRANSLATED
export SCRIPT_FILENAME
exec /opt/rh/php56/root/usr/bin/php-cgi
  

Edit your Apache configuration to let Apache use the FCGI wrapper script.

  
vi /etc/httpd/conf/httpd.conf
  

Below is sample snippet with FCGI implemented inside the Directory tag:

  
<Directory /home/drupal/public_html>
  Options -Indexes +IncludesNOEXEC +SymLinksIfOwnerMatch +ExecCGI
  allow from all
  AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
  Require all granted
  AddType application/x-httpd-php .php
  AddHandler fcgid-script .php
  AddHandler fcgid-script .php5
  AddHandler fcgid-script .php5.6
  FCGIWrapper /home/drupal/fcgi-bin/php5.6.fcgi .php
  FCGIWrapper /home/drupal/fcgi-bin/php5.6.fcgi .php5
  FCGIWrapper /home/drupal/fcgi-bin/php5.6.fcgi .php5.6
</Directory>
  

Comments

i wish i had found this excellent (and now bookmarked) writeup last week. thank you for taking the time to write this.

i would like to add php70 to the environment as well, but php70 does not seem to be quite as easy (yet anyways).

too bad about the imap. i was surprised at that.

i finaly found your great info! thank you so much!!!!!

Hello and thank you for this web article since this is perfect timing due to my creating a new Oracle Enterprise Linux 7.2 Apache web server template and our Web Team is requesting to have PHP 5.6 and PHP 7.0 installed and running for testing purposes.

I have found the following stable PHP versions here - http://php.net/downloads.php:
php-5.6.30.tar.gz
php-7.1.4.tar.gz

I have found this site, but am a little confused with their method: https://oanhnn.github.io/2015-09-22/running-multiple-php-versions-on-single-apache-instance.html

Your information appears to be concise, logical, and straightforward so will give this a shot.

I have installed 5.6 on my server I also still have 5.4 running. I have run scl enable command and php -V brings back version 5.6. I restarted Apache but Apache is still running php 5.4. How do I get Apache to use php 5.6?

Instead of
rpm -Uvh https://www.softwarecollections.org/repos/rhscl/rh-php56/epel-7-x86_64/noarch/rhscl-rh-php56-epel-7-x86_64.noarch.rpm

it should now be
rpm -Uvh https://www.softwarecollections.org/repos/rhscl/rh-php56/epel-7-x86_64/noarch/rhscl-rh-php56-epel-7-x86_64-1-2.noarch.rpm

Hello, now I'm on Apache 2.4.41 for HTTP2, even if on CentOS 7. So, while this worked on the original Apache for Virtualmin on CentOS 7 (I think it was 2.4.6) now it doesn't work on 2.4.41... So what I need to do now "for non-Virtualmin users" ? Thank you

someone has updated version?
rpm -Uvh https://www.softwarecollections.org/repos/rhscl/rh-php56/epel-7-x86_64/noarch/rhscl-rh-php56-epel-7-x86_64-1-2.noarch.rpm

Please try:

      
rpm -Uvh https://vault.centos.org/7.4.1708/sclo/x86_64/rh/rh-php56/rh-php56-2.3-1.el7.x86_64.rpm
      
    

Thank you.

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.