Skip to content

Commit 1e2a3b1

Browse files
committed
Create entrypoint that starts Apache + FPM
1 parent f1f89cb commit 1e2a3b1

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

apache-Dockerfile-block-1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ RUN a2dismod mpm_event && a2enmod mpm_prefork
4444
RUN { \
4545
echo '<FilesMatch \.php$>'; \
4646
echo '\tSetHandler application/x-httpd-php'; \
47+
echo '\t<IfDefine FPM>'; \
48+
echo '\t\tSetHandler "proxy:unix:/var/run/php-fpm/fpm.sock|fcgi://localhost/"'; \
49+
echo '\t</IfDefine>'; \
4750
echo '</FilesMatch>'; \
4851
echo; \
4952
echo 'DirectoryIndex disabled'; \

apache-Dockerfile-block-2

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ RUN set -ex \
2222
echo; echo '; https://github.com/docker-library/php/pull/725#issuecomment-443540114'; echo 'log_limit = 8192'; \
2323
echo; \
2424
echo '[www]'; \
25-
echo '; if we send this to /proc/self/fd/1, it never appears'; \
26-
echo 'access.log = /proc/self/fd/2'; \
27-
echo; \
2825
echo 'clear_env = no'; \
2926
echo; \
3027
echo '; Ensure worker stdout and stderr are sent to the main error log.'; \
@@ -36,8 +33,27 @@ RUN set -ex \
3633
echo 'daemonize = no'; \
3734
echo; \
3835
echo '[www]'; \
39-
echo 'listen = 9000'; \
40-
} | tee php-fpm.d/zz-docker.conf
36+
echo 'listen = /var/run/php-fpm/fpm.sock'; \
37+
echo 'listen.mode = 666'; \
38+
} | tee php-fpm.d/zz-docker.conf \
39+
&& mkdir -p /var/run/php-fpm && chmod 777 /var/run/php-fpm
40+
41+
# Command that launches Apache and FPM simultaneously
42+
RUN { \
43+
echo '#!/bin/bash'; \
44+
echo 'if [ -z "$APACHE_KEEP_MODS" ]; then'; \
45+
echo ' a2dismod -q mpm_prefork php7 && a2enmod -q mpm_event proxy_fcgi || exit 1'; \
46+
echo 'fi'; \
47+
echo 'php-fpm $FPM_ARGS &'; \
48+
echo 'apache2-foreground -DFPM $APACHE_ARGS &'; \
49+
echo; \
50+
echo 'trap "stopped=1" TERM INT'; \
51+
echo 'wait -n # wait until container is stopped, or a process exits'; \
52+
echo 'kill %1 %2 2> /dev/null # send sigterm to remaining processes'; \
53+
echo 'if [ -z "$stopped" ]; then exit 2; fi # if it was a crash, container fails immediately'; \
54+
echo 'until wait; do true; done # otherwise, wait for processes to finish'; \
55+
} | tee /usr/local/bin/apache-fpm \
56+
&& chmod +x /usr/local/bin/apache-fpm
4157

4258
EXPOSE 80
4359
CMD ["apache2-foreground"]

0 commit comments

Comments
 (0)