Skip to content

Commit

Permalink
Fix log file issues
Browse files Browse the repository at this point in the history
- when running in docker, php-fpm child proceses can't write to log
  files which are symbolic linked to /dev/stderr.  seems to be
  related to permissions and how cake/php uses fopen when writing to
  pipes.
- this fix create pipes before starting the php-fpm master process.
  these pipes are redirected to stderr
  • Loading branch information
kitsook committed Jan 18, 2021
1 parent d1571ff commit 1f1032b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
7 changes: 3 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,18 @@ RUN apt-get update && apt-get install --no-install-recommends --no-install-sugge

COPY docker/php.ini /usr/local/etc/php/
COPY . /var/www/html
COPY docker/docker-entrypoint-php-fpm.sh /

RUN cd /var/www/html \
&& composer install --no-ansi --no-dev --no-interaction --no-plugins --no-progress --no-suggest --optimize-autoloader \
&& mkdir -p /var/www/html/app/tmp/cache/persistent /var/www/html/app/tmp/cache/models /var/www/html/app/tmp/logs \
&& chown www-data:www-data -R /var/www/html/app/tmp/cache \
&& ln -sf /dev/stdout /var/www/html/app/tmp/logs/api.log \
&& ln -sf /dev/stdout /var/www/html/app/tmp/logs/debug.log \
&& ln -sf /dev/stdout /var/www/html/app/tmp/logs/login.log \
&& ln -sf /dev/stderr /var/www/html/app/tmp/logs/error.log
&& chown www-data:www-data -R /var/www/html/app/tmp/logs

RUN set -ex \
## Customize PHP fpm configuration
&& sed -i -e "s/;clear_env\s*=\s*no/clear_env = no/g" /usr/local/etc/php-fpm.conf \
&& sed -i -e "s/;request_terminate_timeout\s*=[^\n]*/request_terminate_timeout = 300/g" /usr/local/etc/php-fpm.conf \
&& php-fpm --test

CMD ["/docker-entrypoint-php-fpm.sh"]
17 changes: 17 additions & 0 deletions docker/docker-entrypoint-php-fpm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh

# hacks to allow php-fpm child process to write to log files that redirected to stderr
# similar to https://github.com/moby/moby/issues/6880#issuecomment-344114520
chown www-data:www-data /var/www/html/app/tmp/logs
for f in /var/www/html/app/tmp/logs/api.log \
/var/www/html/app/tmp/logs/debug.log \
/var/www/html/app/tmp/logs/error.log \
/var/www/html/app/tmp/logs/login.log
do
rm -f $f
mkfifo -m 600 $f
chown www-data:www-data $f
cat <> $f 1>&2 &
done

php-fpm

0 comments on commit 1f1032b

Please sign in to comment.