PHP-FPM in Docker
+
Par Remi le jeudi 11 décembre 2014, 14:31 - HowTo - Lien permanent
Use case : running php 5.3.3 on a Fedora 20 / 21 development workstation, for production deployment on RHEL-6 (as no php 5.3 SCL exists).
This example can be easily adapted for all available PHP versions available as RPM (5.3.3 in RHEL-6, 5.4.16 in RHEL-7, 5.4.16 and 5.5.6 in RHSCL 1.2 or using a third party repository).
I use this Dockerfile:
FROM centos:6
RUN yum -y update && yum clean all
RUN yum -y install php-fpm php-mbstring php-mysql php-gd && yum clean all
RUN sed -e 's/127.0.0.1:9000/9000/' \
-e '/allowed_clients/d' \
-e '/catch_workers_output/s/^;//' \
-e '/error_log/d' \
-i /etc/php-fpm.d/www.conf
RUN mkdir -p /var/www/html
EXPOSE 9000
ENTRYPOINT /usr/sbin/php-fpm --nodaemonize
Installation:
- yum install allow to use the available packages, extension list need to be adapted to suite your need
- the /var/www/html directory used here need to be adapted, according to your scripts location
Changes applied to the fpm pool configuration:
- listen = 9000 to listen on all interfaces
- remove listen.allowed_clients to allow connection from outside the container
- remove error_log to use global error recording
- enable catch_workers_ouput to catch the pool error in the main server
Creation of the container:
docker build -t fpm53 .
Launching the container:
docker run -v /var/www/html:/var/www/html -p 127.0.0.1:9003:9000 fpm53
Notice : /var/www/html directory and port 9000 (in container) mapped to port 9003 (in host)
Conclusion
Even if I'm a fervent supporter of Software Collections, when missing, we have a very simple way to get an operational PHP version 5.3.3 on a recent distribution (tested on Fedora 20) with the benefit of using official repository.
Commentaires
PHP 5.3 has reached end of life in August 2014.
@apehanger but is maintained in RHEL / CentOS 6.
The reason why I use, in this example, "official" packages from EL-6, and not from other sources.
Also on http://developerblog.redhat.com/