I am experimenting with Docker and want to move from a local MAMP stack to Docker. Of course I stumbled upon the official php:7.0
image but I want to use Apache as well so it seems as if php:7.0-apache
is the way to go. However I saw that there is an image called php:7.0-alpine
which is much slimmer while there are two versions for Apache as well namely httpd:2.4
and httpd:2.4-alpine
.
Is there any suggested combination to use both Apache and PHP (either separated or combined) while still having small image sizes? Furthermore I would like to know where I can review the available modules in the images since I want to use MariaDB and mod_rewrite as well which could possibly have more dependencies which have been omitted to keep the size small.
I came across this very detailed and awesome tutorial on how to split up nginx and PHP as well as MySQL into different containers but attach PHP to nginx using FCGI. This implies that I can use all the different alpine-based images of the tools and link them using FCGI. Unfortunately I have never heard of or worked with FCGI but I guess some more research will yield information on how to implement this infrastructure using Apache.
In addition to helmberts proposed solution which worked for me I was fiddling around with the official httpd:2.4-alpine
image. I want to add some more information and caveats I stumbled upon while working on this.
a2en*
and no a2dis*
scripts./etc/apache2
. Everything is in /usr/local/apache2
and you have your global httpd.conf
in /usr/local/apache2/conf/
. In this file you have to uncomment the module lines manually to load them as well as further configuration files like httpd-vhosts.conf
which is stored in /usr/local/apache2/conf/extra/
.httpd-vhosts.conf
to setup the basic options for my testing:<VirtualHost *:80>
DocumentRoot /usr/local/apache2/htdocs
<Directory /usr/local/apache2/htdocs>
Options -Indexes +FollowSymLinks -MultiViews
AllowOverride All
Require all granted
</Directory>
ErrorLog /usr/local/apache2/main-error.log
LogLevel warn
CustomLog /usr/local/apache2/main-access.log combined
</VirtualHost>
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
./bin/apachectl restart
as usual assuming you are in /usr/local/apache2
.nano
I had to install it manually using apk --no-cache add nano
. This can be done in an interactive session or globally using a Dockerfile
to fork the base image.nano
- in my case I had to export TERM=xterm
in an interactive shell or ENV TERM xterm
in the Dockerfile
.php-fpm
has to have access to the very same files - this is something I didn't actually notice in the proposed solution at first. This means as well that I had the source files mounted at two different paths (/usr/local/apache2/htdocs
in the httpd
image and /var/www/html
in the php-fpm
image) and had to forward calls properly. I used the following line in the httpd.conf
.ProxyPassMatch "^/(.*\.php)$" "fcgi://fpm:9000/var/www/html/$1"
fpm
name in the FCGI link is the name of my container that is linked to httpd
using --link fpm
and automatically added to the /etc/hosts
.Dockerfile
using either COPY
commands or applying basic sed
calls.SetHandler "proxy:unix:/var/run/php7-fpm.sock|fcgi://fpm/"
but I don't know if that is useful or not.