No php-fpm error logs from docker container
Asked Answered
F

4

18

Using apache + php-fpm containers in docker-compose, I can't get the php-fpm container to display any errors.

docker-compose.yml

version: '3'

services:
  php:
    build:
      context: ./php
    ports:
      - 9000:9000
    volumes:
      - ./code:/code
      - ./php/www.conf:/usr/local/etc/php-fpm.d/www.conf
    environment:
      ENVIRONMENT: local
  web:
    image: httpd:2.4
    depends_on:
      - php
    ports:
      - 80:80
    volumes:
      - ./code:/usr/local/apache2/htdocs
      - ./web/httpd.conf:/usr/local/apache2/conf/httpd.conf
    depends_on:
      - php

php-fpm Dockerfile:

FROM php:5.6-fpm 

php-fpm www.conf:

[global]
error_log = /proc/self/fd/2

[www]

user = www-data
group = www-data

listen = nginx:9000

pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3

; Logging

; if we send this to /proc/self/fd/1, it never appears
access.log = /proc/self/fd/2

clear_env = no

; Ensure worker stdout and stderr are sent to the main error log.
catch_workers_output = yes

php_flag[display_errors] = on
php_admin_flag[log_errors] = on
;php_admin_value[error_log] = /var/log/fpm-php.www.log
php_admin_value[error_reporting] = E_ALL & ~E_NOTICE & ~E_WARNING & ~E_STRICT & ~E_DEPRECATED
php_admin_value[display_startup_errors] = on

docker-compose logs only shows php-fpm access logs, no error logs.

Tried all solutions proposed in post proposed as possible duplicate: PHP-FPM doesn't write to error log None of them worked for me, check my comments down below.

Forrestforrester answered 21/11, 2018 at 17:25 Comment(11)
Possible duplicate of PHP-FPM doesn't write to error logBabysitter
That poster is not using Docker?Forrestforrester
Shouldn't really make a difference @ForrestforresterAwn
Personally I specify my error log location under php.ini conf.d in a vhosts.ini file. I've had no issues with it, I'm using the php 7.2 version of the same image as you. Can you check that your conf files have all taken affect by "ssh"ing into your container docker exec -it {php container name} bash and running all the needed commands/tests.Awn
I already have this directive "catch_workers_output = yes" present. Check the www.conf I posted.Forrestforrester
Also, there's no /var/log/upstart/php5-fpm.log inside the container.Forrestforrester
Next comment there, creating the error log file manually, with the touch command, doesn't apply here, since error_log is redirected to stderr, error_log = /proc/self/fd/2. And I already have the php_admin_flag[log_errors] = on directive in www.conf.Forrestforrester
Next up, the php-fpm bug doesn't affect my usecase, since I use php-fpm 5.6, bugs.php.net/bug.php?id=61045.Forrestforrester
I went through all the comments/solutions there. Already tried them all, as is evident by the config I posted. None of them work for me.Forrestforrester
Hello from the future. How are you handling php-fpm logging in docker right now? Please & thank you for any help @ForrestforresterKassel
Hi @emmdee. I went to work on a different project, so I haven't spent more time trying to figure this out. I'm using fluentd to scrape the logs from app containers.Forrestforrester
B
3

In my case it was the /usr/local/etc/php-fpm.d/docker.conf which caused the troubles:

[global]
error_log = /proc/self/fd/2

; https://github.com/docker-library/php/pull/725#issuecomment-443540114
log_limit = 8192

[www]
; if we send this to /proc/self/fd/1, it never appears
access.log = /proc/self/fd/2

clear_env = no

; Ensure worker stdout and stderr are sent to the main error log.
catch_workers_output = yes
decorate_workers_output = no

The error_log directive's value of /proc/self/fd/2 causes the log being written into the terminal/console where the docker-compose up is running.

I just had to create a custom global fpm config file within the /usr/local/etc/php-fpm.d/ directory and make it execute as the last one by naming it zz-global.conf, so it can override the docker.conf values. Then I just needed to set the value for the error_log to a custom path within the php-fpm container e.g.:

[global]
error_log = /var/www/logs/php-fpm-error.log

That's it.

Maybe worth mentioning: my php.ini (modified php.ini-development) has following custom error logging related values:

; https://mcmap.net/q/135046/-php-fpm-doesn-39-t-write-to-error-log
; Redirect worker stdout and stderr into main error log. If not set, stdout and
; stderr will be redirected to /dev/null according to FastCGI specs.
; Default Value: no
catch_workers_output = yes
php_admin_flag[log_errors] = on
php_admin_flag[display_errors] = on
php_admin_value[error_reporting] = E_ALL
php_admin_value[error_log] = /var/log/error.log
access.log = /var/www/logs/php-fpm-access.log

Buffoon answered 9/10, 2021 at 19:4 Comment(3)
The error logs are supposed to go to the container stdout/stderr just like the OP wants, writing the logs to a regular file is not a solution to the problem in the question.Palaeozoic
I can't see from the OP any clear preferences about where the log has to go. As far as I interpreted the question it's about getting to see any error info at all. Nut sure why you have to point out your personal view of the question as the non plus ultra perspective. Still my answer might point in the right direction even if the OP thought exactly as you think.Buffoon
I apologize if I did not make it clear that it's not about preferences, op says "docker-compose logs only shows php-fpm access logs, no error logs". They are indeed after logs on stdout, not logs in a file.Palaeozoic
D
2

Struggle hours to get this working.

In the file docker-compose.yml I mounted my logs (so they persist)

        volumes:
        - ./phpSettings.conf:/usr/local/etc/php-fpm.d/zzz-phpSettings.conf
        - ./logs/php-error.log:/var/log/error.log
        - ./logs/php-access.log:/var/log/access.log

In the phpSettings.conf file I have this:

[www]
user = www-data
group = www-data
listen = 0.0.0.0:9000
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3

catch_workers_output = yes
php_admin_flag[log_errors] = on
php_admin_flag[display_errors] = off
php_admin_value[error_reporting] = E_ALL & ~E_NOTICE & ~E_WARNING & ~E_STRICT & ~E_DEPRECATED
php_admin_value[error_log] = /var/log/error.log
access.log = /var/log/access.log
php_value[memory_limit] = 512M
php_value[post_max_size] = 24M
php_value[upload_max_filesize] = 24M

Make sure the mounted log files exist before starting the docker.

the trick seems to be naming my settings zzz-phpSettings.conf so is the last one to load. I overwrite the default docker php image www.conf settings with the very same settings (except the listen 0.0.0.0:9000).

In this php-fpm+Nginx setup I managed to have nginx (error/access) logs to its own location + php-fpm error/access logs to its own place too, so loggins looks really nice.

Dotterel answered 25/8, 2019 at 17:11 Comment(4)
This works to get logs out into persistent files but the docker logging driver knows nothing about it. The original question stated "docker-compose logs" didn't show the error logs. Any idea how to solve that problem?Kassel
my docker compose shows logs with this setup, the apache error logs are directed to the files mentioned. Also, I don't agree this question was about seeing the logs in docker-compose.Dotterel
Specifically stated in the question: "docker-compose logs only shows php-fpm access logs, no error logs." so trying to get the error logs in docker logging driver. If you have any advice would appreciate it trying to solve this myself as well.Kassel
And also said that: Tried all solutions proposed in post proposed as possible duplicate --- which is writing logs to a file, indicating that he is ok with that and not only looking for docker compose logs. :PDotterel
G
0

In my case it was a php script calling:

error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED);
ini_set('display_errors', ...);
ini_set('log_errors', ...);
ini_set("error_log", ...);

which overrided global php settings. So sometimes you also need to check your php files.

Gayl answered 3/11, 2023 at 12:15 Comment(0)
J
0

Because the configuration for using in docker, usually the target program will generate error into STDERR.

The "docker logs" command will dump the log gotten from the original STDOUT by default; if you want to check the log from original STDERR, you must use this command:

docker logs -f {container name here} > /dev/null

this is to direct the original STDOUT to /dev/null and then the log from STDERR comes out

Juicy answered 14/8, 2024 at 11:35 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.