PROJET AUTOBLOG


Planet-Libre

source: Planet-Libre

⇐ retour index

Remi Collet : Plusieurs versions de PHP sur un serveur Apache 2.4

jeudi 7 novembre 2013 à 15:15

Pour illustrer ma conférence Introduction aux Software Collections, j'ai fait la démonstration sur l'utilisation d'un frontal Apache fonctionnant simultanément avec 3 versions de PHP (5.3, 5.4 et 5.5).

Gros plan sur cette mise en oeuvre très simple sur RHEL 6 ou CentOS 6.

Bien sur cette configuration peut s'appliquer à toutes les distributions, à condition de pouvoir installer plusieurs versions en parallèle ou de savoir compiler les sources. C'est juste plus facile avec les SCL.

J'ai évidement utiliser les paquets disponibles en SCL sur le site du projet SoftwareCollections, en particulier les collections httpd24, php54 et php55.

Installation du dépôt RHSCL 1.0 sur RHEL-6 (pour php54)

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

Installation du dépôt php54 sur CentOS-6

wget http://people.redhat.com/rcollet/php54/rhel-php54.repo -O /etc/yum.repos.d/php54.repo

Installation du dépôt httpd24 :

wget http://repos.fedorapeople.org/repos/jkaluza/httpd24/epel-httpd24.repo -O /etc/yum.repos.d/httpd24.repo

Installation du dépôt php55 :

wget http://people.redhat.com/rcollet/php55/rhel-php55.repo -O /etc/yum.repos.d/php55.repo

Installation des paquets Apache 2.4.6, PHP 5.3.3, 5.4.16 et 5.5.5 :

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

Comme les 3 versions de php-fpm sont configurées pour écouter sur le port 9000, modifions cela :

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

Configuration d'apache pour qu'il demande l'exécution des scripts PHP à FPM en fonction de la version, en créant le fichier /opt/rh/root/etc/httpd/conf.d/fpm.conf

#   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

J'ai choisi de rediger les 3 URL vers le même dossier, car mon objectif est de tester la même application avec les différentes versions de PHP.

J'aurais aussi pu configurer 3 hôtes virtuels.

Installons notre application préférée:

mkdir /srv/website
echo '/srv/website/info.php

Démarrage des services

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

Il ne reste plus qu'à profiter : http://localhost/php53/info.php ou http://localhost/php54/info.php ou http://localhost/php55/info.php

A noter, il s'agit d'une configuration simpliste, destinée a un développeur désirant faire des tests. Elle nécessiterait d'être améliorée pour une utilisation en production, mais le principe reste le même.

Gravatar de Remi Collet
Original post of Remi Collet.Votez pour ce billet sur Planet Libre.