Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Draft] Add mpm_event / FPM support to apache variant #785

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion apache-Dockerfile-block-1
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ RUN a2dismod mpm_event && a2enmod mpm_prefork
RUN { \
echo '<FilesMatch \.php$>'; \
echo '\tSetHandler application/x-httpd-php'; \
echo '\t<IfDefine FPM>'; \
echo '\t\tSetHandler "proxy:unix:/var/run/php-fpm/fpm.sock|fcgi://localhost/"'; \
echo '\t</IfDefine>'; \
echo '</FilesMatch>'; \
echo; \
echo 'DirectoryIndex disabled'; \
Expand All @@ -57,4 +60,4 @@ RUN { \
&& a2enconf docker-php

ENV PHP_EXTRA_BUILD_DEPS apache2-dev
ENV PHP_EXTRA_CONFIGURE_ARGS --with-apxs2 --disable-cgi
ENV PHP_EXTRA_CONFIGURE_ARGS --with-apxs2 --disable-cgi --enable-fpm --with-fpm-user=www-data --with-fpm-group=www-data
45 changes: 45 additions & 0 deletions apache-Dockerfile-block-2
Original file line number Diff line number Diff line change
@@ -1,5 +1,50 @@
COPY apache2-foreground /usr/local/bin/
WORKDIR /var/www/html

# Set up FPM
RUN set -ex \
&& cd /usr/local/etc \
&& if [ -d php-fpm.d ]; then \
# for some reason, upstream's php-fpm.conf.default has "include=NONE/etc/php-fpm.d/*.conf"
sed 's!=NONE/!=!g' php-fpm.conf.default | tee php-fpm.conf > /dev/null; \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

| tee php-fpm.conf > /dev/null seems super pointless, just redirect to > php-fpm.conf directly?

Copy link
Author

@mildsunrise mildsunrise Dec 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! These lines were copied directly from the current FPM dockerfile.
I think these corrections should be done there first, in order to not maintain different versions of the snippet.

cp php-fpm.d/www.conf.default php-fpm.d/www.conf; \
else \
# PHP 5.x doesn't use "include=" by default, so we'll create our own simple config that mimics PHP 7+ for consistency
mkdir php-fpm.d; \
cp php-fpm.conf.default php-fpm.d/www.conf; \
{ \
echo '[global]'; \
echo 'include=etc/php-fpm.d/*.conf'; \
} | tee php-fpm.conf; \
fi \
&& { \
echo '[global]'; \
echo 'error_log = /proc/self/fd/2'; \
echo; echo '; https://github.com/docker-library/php/pull/725#issuecomment-443540114'; echo 'log_limit = 8192'; \
echo; \
echo '[www]'; \
echo 'clear_env = no'; \
echo; \
echo '; Ensure worker stdout and stderr are sent to the main error log.'; \
echo 'catch_workers_output = yes'; \
echo 'decorate_workers_output = no'; \
} | tee php-fpm.d/docker.conf \
&& { \
echo '[global]'; \
echo 'daemonize = no'; \
echo; \
echo '[www]'; \
echo 'user = ${FPM_RUN_USER}'; \
echo 'group = ${FPM_RUN_GROUP}'; \
echo 'listen = /var/run/php-fpm/fpm.sock'; \
echo 'listen.mode = 666'; \
} | tee php-fpm.d/zz-docker.conf \
&& mkdir -p /var/run/php-fpm \
# allow running as an arbitrary user
&& chmod 777 /var/run/php-fpm

# Provide alternate command to start Apache with FPM
COPY apache-fpm /usr/local/bin/

EXPOSE 80
CMD ["apache2-foreground"]
30 changes: 30 additions & 0 deletions apache-fpm
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

# By default, FPM will run as the same user as Apache
. "$APACHE_ENVVARS"
: ${FPM_RUN_USER:=$APACHE_RUN_USER}
: ${FPM_RUN_GROUP:=$APACHE_RUN_GROUP}
export FPM_RUN_USER FPM_RUN_GROUP

# Strip off any '#' symbol ('#1000' is valid syntax for Apache)
pound='#'
FPM_RUN_USER="${FPM_RUN_USER#$pound}"
FPM_RUN_GROUP="${FPM_RUN_GROUP#$pound}"

# Setup Apache modules and launch!
if [ -z "$APACHE_KEEP_MODS" ]; then
a2dismod -q mpm_prefork php7 && a2enmod -q mpm_event proxy_fcgi || exit 1
fi
php-fpm $FPM_ARGS &
apache2-foreground -DFPM "$@" &

# Wait until container is stopped, or a process crashes
trap "stopped=1" TERM INT
wait -n

# Tell processes to terminate
kill %1 %2 2> /dev/null
# If there was a crash, container fails immediately
if [ -z "$stopped" ]; then exit 2; fi
# If the container was stopped, wait for processes to finish
until wait; do true; done
4 changes: 2 additions & 2 deletions update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ for version in "${versions[@]}"; do
docker-php-source \
"$version/$suite/$variant/"
if [ "$variant" = 'apache' ]; then
cp -a apache2-foreground "$version/$suite/$variant/"
cp -a apache2-foreground apache-fpm "$version/$suite/$variant/"
fi
if [ "$majorVersion" = '7' -a "$minorVersion" -lt '2' ] || [ "$suite" = 'jessie' ]; then
# argon2 password hashing is only supported in 7.2+ and stretch+ / alpine 3.8+
Expand All @@ -159,7 +159,7 @@ for version in "${versions[@]}"; do
# sodium is part of php core 7.2+ https://wiki.php.net/rfc/libsodium
sed -ri '/sodium/d' "$version/$suite/$variant/Dockerfile"
fi
if [ "$variant" = 'fpm' -a "$majorVersion" = '7' -a "$minorVersion" -lt '3' ]; then
if [ "$variant" = 'fpm' -o "$variant" = 'apache' ] && [ "$majorVersion" = '7' -a "$minorVersion" -lt '3' ]; then
# php-fpm "decorate_workers_output" is only available in 7.3+
sed -ri \
-e '/decorate_workers_output/d' \
Expand Down