1

I'm using php-fpm with Caddy and I cannot make php-fpm log errors. Previously I used nginx and nginx captures and displays php errors in its own logs quite nicely, so I never had an issue, but with caddy I decided to enable php-fpm error log, and it just... doesn't work. But let's start from the beginning:

OS: Ubuntu 22.04.1

App: Symfony 7.1 with monolog (mentioning it in case it stops error propagation or whatever)

Caddy v2.8.4 config:

[REDACTED] { tls [REDACTED] root * [REDACTED] file_server php_fastcgi unix//var/run/php/php8.3-fpm.sock log { output file /var/log/caddy/[REDACTED].log level ERROR } 

php-fpm 8.3.12 pool configuration:

 listen = /var/run/php/php8.3-fpm.sock listen.owner = [REDACTED] listen.group = www-data pm = dynamic pm.max_children = 5 pm.start_servers = 2 pm.min_spare_servers = 1 pm.max_spare_servers = 3 user = [REDACTED] group = www-data php_value[memory_limit] = 8G catch_workers_output = yes php_flag[display_errors] = on php_admin_value[error_log] = /var/log/php-fpm/[REDACTED].log php_admin_flag[log_errors] = on 

The main php-fpm log works just fine, but it just contains information about service restarts basically, so it's not very useful. The log belonging to the pool is not saved.

What I did:

  • I made sure that permissions and ownership of the log files are correctly set. Log file exists. I touched it, and copy-pasted paths to avoid any typos. The /var/log/php-fpm directory is 777 just as the log file. It's temporary to exclude any permission reasons.
  • I can see in phpinfo that values set in the pool configuration take effect.
  • I restarted everything.
  • When I visit a page returning error 500, no log is saved. The logs file is always empty.

enter image description here

Is there anything else am I missing? Does anyone have any idea where I could look at, to figure this out?

1 Answer 1

0

I figured it out. To debug this, I introduced a syntax error in the index.php file. I did this to exclude the possibility of Symfony's meddling, and lo and behold: the error was logged. This indicated that it's Symfony that is using its own error handler.

Basically, in dev environment all errors being logged in the [project's root]/var/logs/dev.log file, as per monolog default configuration:

when@dev: monolog: handlers: main: type: stream path: "%kernel.logs_dir%/%kernel.environment%.log" level: debug channels: ["!event"] # uncomment to get logging in your browser # you may have to allow bigger header sizes in your Web server configuration #firephp: # type: firephp # level: info #chromephp: # type: chromephp # level: info console: type: console process_psr_3_messages: false channels: ["!event", "!doctrine", "!console"] 

On prod environment though, the logs are being sent to stderr:

when@prod: monolog: handlers: main: type: fingers_crossed action_level: error handler: nested excluded_http_codes: [404, 405] buffer_size: 50 # How many messages should be saved? Prevent memory leaks nested: type: stream path: php://stderr level: debug formatter: monolog.formatter.json console: type: console process_psr_3_messages: false channels: ["!event", "!doctrine"] deprecation: type: stream channels: [deprecation] path: php://stderr formatter: monolog.formatter.json 

So yeah, Symfony basically handles errors itself, so php-fpm is not logging them.

Here is a post of the Symfony's author about why logging to stderr is recommended: https://symfony.com/blog/logging-in-symfony-and-the-cloud

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.