Skip to content

Commit 1f1032b

Browse files
committed
Fix log file issues
- 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
1 parent d1571ff commit 1f1032b

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

Dockerfile

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,18 @@ RUN apt-get update && apt-get install --no-install-recommends --no-install-sugge
1818

1919
COPY docker/php.ini /usr/local/etc/php/
2020
COPY . /var/www/html
21+
COPY docker/docker-entrypoint-php-fpm.sh /
2122

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

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

35+
CMD ["/docker-entrypoint-php-fpm.sh"]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/sh
2+
3+
# hacks to allow php-fpm child process to write to log files that redirected to stderr
4+
# similar to https://github.com/moby/moby/issues/6880#issuecomment-344114520
5+
chown www-data:www-data /var/www/html/app/tmp/logs
6+
for f in /var/www/html/app/tmp/logs/api.log \
7+
/var/www/html/app/tmp/logs/debug.log \
8+
/var/www/html/app/tmp/logs/error.log \
9+
/var/www/html/app/tmp/logs/login.log
10+
do
11+
rm -f $f
12+
mkfifo -m 600 $f
13+
chown www-data:www-data $f
14+
cat <> $f 1>&2 &
15+
done
16+
17+
php-fpm

0 commit comments

Comments
 (0)