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:
Login as root to your server's console terminal.
Install the Software Collections utilities:
yum install scl-utils
Install the PHP version 5.6 RPM repository package for CentOS 7:
rpm -Uvh https://www.softwarecollections.org/repos/rhscl/rh-php56/epel-7-x86_64/noarch/rhscl-rh-php56-epel-7-x86_64.noarch.rpm
Install the PHP package:
yum install rh-php56
(Optional) To start using Software Collections with new bash instance with PHP version 5.6:
scl enable rh-php56 bash
To verify it:
You should see the PHP version 5.6 instead of system's default version.
The log file can be found at
Setup Apache to use the PHP 5.6 version for Virtualmin users:
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
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)
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:
- 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:
#!/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.
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>