Apache with various PHP versions, using SCL

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://127.0.0.1:9000/srv/website
# Other static stuff
Alias /php53 /srv/website

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

ProxyPassMatch ^/php55/(.*.php)$ fcgi://127.0.0.1:9003/srv/website
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.

Share
  • Aparna D

    Does RHEL6.6 support PHP5.5 on Apache2.4? I get segmentation faults in all environments dev as well as prod

  • I am uncertain if my comment post made it and is pending approval or if it just failed.
    I am trying to set up Apache 2.4 and PHP 5.6 from RHSC alongside Apache 2.2 and PHP 5.3. For this version of PHP they have changed the naming convention and the base directory to rh-php56. I cannot find /opt/rh/rh-php56/root/etc/php-fpm.d/www.conf. I am stuck at step 2.

    And the interface for comments on this system sucks. I keep getting sent to a WordPress sign on page and I have no interest in blogging here.

    • Remi Collet

      Since rh-php56, configuration is located under /etc/opt/rh-php56 (which is more FHS compliant)

  • I have been browsing online more than 2 hours today, yet I never found any interesting article
    like yours. It is pretty worth enough for me.
    Personally, if all website owners and bloggers made good content as you did, the internet will be much more useful than ever before. http://bing.co.uk

  • It is the best time to make a few plans for the long run and it’s time to be happy.
    I’ve learn this publish and if I may just I desire to suggest you few interesting things or suggestions.
    Perhaps you could write next articles referring to this article.
    I want to learn even more things about it! http://yahoo.org

  • I have been surfing online more than 3 hours today, yet I never
    found any fascinating article like yours. It is beautiful worth sufficient for me.

    Personally, if all web owners and bloggers made good content as you did, the web might be much more helpful than ever before. http://bing.co.uk

  • Greetings from Idaho! I’m bored at work so I decided to browse
    your website on my iphone during lunch break. I really like
    the information you provide here and can’t wait to take a look
    when I get home. I’m shocked at how quick your blog loaded on my mobile ..
    I’m not even using WIFI, just 3G .. Anyways, very good site! http://yahoo.net

  • I’ve been surfing online more than 3 hours today, yet I never found
    any interesting article like yours. It is pretty worth enough for me.
    In my view, if all web owners and bloggers made good content as you did, the net will
    be much more useful than ever before. http://yahoo.net

  • I really like it whenever people get together and share ideas.
    Great blog, stick with it! http://yahoo.net

  • I couldn’t resist commenting. Very well written! http://yahoo.co.uk