Various PHP versions with an Apache 2.4 server
+
Par Remi le jeudi 7 novembre 2013, 15:38 - RPM - Lien permanent
For my talk about Software Collections Introduction I done a demonstration on using a single Apache web server running simultaneously 3 PHP versions (5.3, 5.4 et 5.5).
Here is an how to implement this on RHEL 6 or CentOS 6.
Of course this configuration can be used on all distributions, if you can install various versions of the same application, or if you know how to build from sources. It's just easier with SCL.
Of course, I use the available SCL pakages from the SoftwareCollections project site, especially the httpd24, php54 and php55 collections.
RHSCL 1.0 repository configuration for RHEL-6 (php54):
rhn-channel --add --channel=rhel-x86_64-server-6-rhscl-1
php54 repository configuration on CentOS-6 as RHSCL-1.0 is not (yet ?) backported:
wget http://people.redhat.com/rcollet/php54/rhel-php54.repo -O /etc/yum.repos.d/php54.repo
httpd24 repository configuration:
wget http://repos.fedorapeople.org/repos/jkaluza/httpd24/epel-httpd24.repo -O /etc/yum.repos.d/httpd24.repo
php55 repository configuration :
wget http://people.redhat.com/rcollet/php55/rhel-php55.repo -O /etc/yum.repos.d/php55.repo
Apache 2.4.6, PHP 5.3.3, 5.4.16 and 5.5.5 packages installation:
yum install httpd24 php54 php54-php-fpm php55 php55-fpm php-fpm
As the 3 php-fpm versions are configured to listen on the same port I have to change this:
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
Apache configuration for delegating the PHP scripts execution to a php-fpm back-end, according to the version, The new /opt/rh/root/etc/httpd/conf.d/fpm.conf file:
# PHP script 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
I choose to configure the 3 URL to serve the same folder as my goal is to test the same applilcation with various PHP versions.
I could also have configured various virtual hosts.
Prefered web application installation:
mkdir /srv/website
echo '<?php phpinfo()' >/srv/website/info.php
Required services start up:
service httpd24-httpd start
service php-fpm start
service php54-php-fpm start
service php55-php-fpm start
Just enjoy: http://localhost/php53/info.php or http://localhost/php54/info.php or http://localhost/php55/info.php
Notice: this is a very simple configuration, for development/testing purpose. It will requiring more tunning to be used in production, but it's working.
Commentaires
Listed repositories are no more available.
RHEL users can use RHSCL 1.1 Beta and CentOS users the Copr repositories, see Red Hat will provide PHP 5.5 for RHEL-6