RHSCL 1.1 Beta is available and provides Apache httpd 2.4, PHP 5.4 and PHP 5.5.

The most common configuration for Apache and PHP uses mod_php, but this only allows a single PHP version. Apache httpd 2.4 introduces mod_proxy_fgci which can simply redirect requests to a php-fpm backend.

This article shows a simple way to use a single Apache server and simultaneously run 3 versions of PHP (5.3, 5.4 and 5.5). The same site will be served through 3 sub-URL.

 1. Installation

RHEL-6 users just have to enable the RHSCL 1.1 beta channel:

rhn-channel --add --channel=rhel-x86_64-server-6-rhscl-1-beta

Other users can configure the Copr development repositories:

wget http://copr.fedoraproject.org/coprs/rhscl/httpd24/repo/epel-6-x86_64/ 
     -O /etc/yum.repos.d/rhscl-httpd24.repo
wget http://copr.fedoraproject.org/coprs/rhscl/php54/repo/epel-6-x86_64/ 
     -O /etc/yum.repos.d/rhscl-php54.repo
wget http://copr.fedoraproject.org/coprs/rhscl/php55/repo/epel-6-x86_64/ 
     -O /etc/yum.repos.d/rhscl-php55.repo

And then install the needed packages:

yum install httpd24 php54 php54-php-fpm php55 php55-php-fpm php-fpm

2. FPM configuration

As all the FPM servers are configured by default to listen on port 9000, we have to change this and adapt SELinux to allow connection.

sed -e 's/9000/9002/' -i /opt/rh/php54/root/etc/php-fpm.d/www.conf
semanage port -a -t http_port_t -p tcp 9002

sed -e 's/9000/9003/' -i /opt/rh/php55/root/etc/php-fpm.d/www.conf
semanage port -a -t http_port_t -p tcp 9003

3. Apache configuration

We delegate execution of PHP scripts to the FPM servers, adding rules for each version, in the new /opt/rh/root/etc/httpd/conf.d/fpm.conf file:

# PHP scripts executed by FPM backend
ProxyPassMatch ^/php53/(.*.php)$ fcgi://
# Other static stuff
Alias /php53 /srv/website

ProxyPassMatch ^/php54/(.*.php)$ fcgi://
Alias /php54 /srv/website

ProxyPassMatch ^/php55/(.*.php)$ fcgi://
Alias /php55 /srv/website

Notice: we use /srv/website as the root tree of our test site.

4. Starting the services

service httpd24-httpd start
service php54-php-fpm start
service php55-php-fpm start

5. Playing

You can now access the same site through the 3 URL, each running a different PHP version:

  • http://<servername>/php53/
  • http://<servername>/php54/
  • http://<servername>/php55/

6. Outcome

This very simple configuration is obviously not production ready, but will be useful for web developers to ensure their application runs with various PHP versions, or for system administrators wanting to test / prepare a system upgrade.

7. Additional tip

RHSCL php54 and php55 collections provide a common set of extensions. Some other extensions can be found in the php54more and php55more experimental community maintained repositories.

Last updated: November 2, 2023