Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

PHP-FPM runs, but no PHP errors show up in any log file

ErrorPHP-FPM doesn't write to error log

Short answer

PHP-FPM only logs script errors when log_errors is on, and it needs a log file the pool user can write. Print log_errors and error_log through FPM itself, not the CLI. Then fix the one that is off or unwritable. Worker stdout and stderr are discarded unless catch_workers_output is yes.

  • Applies to PHP 8.3, PHP 8.4, PHP-FPM, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Ask PHP-FPM, not the command line, what it uses. Put this probe in the web root, request it through your web server, then delete it.

    <?php
    // probe.php: request it in the browser, then remove it
    var_dump(ini_get('log_errors'), ini_get('error_log'));
    error_log('fpm probe line');
  2. 2Match what you see, then jump to its fix

    1. 1The probe prints string(1) "0" or an empty value for log_errors.log_errors is offFix
    2. 2error_log prints a path, but the file is missing or owned by another user.error_log points at a file the FPM user cannot writeFix
    3. 3You set error_log in php.ini, yet the probe prints a different path.A pool setting overrides the php.ini you editedFix
    4. 4Output written to stdout or stderr by a script never appears, while PHP errors do.Worker output is thrown awayFix

What does the error look like?

  • PHP-FPM doesn't write to error log
  • A script fails with HTTP 500 and the error log has no matching line
  • error_log() calls leave no trace in php-fpm.log

Cause 1 of 4

log_errors is off

1Check

The manual lists the default of log_errors as 0, so a php.ini that never sets it logs nothing. Compare the value the probe printed.

curl -s http://localhost/probe.php

2Fix

Turn it on in the php.ini that FPM loads (phpinfo() on a page shows its path), then restart FPM.

; php.ini used by FPM
log_errors = On

3Verify

Request the probe again; log_errors prints as 1.

sudo systemctl restart php8.3-fpm
curl -s http://localhost/probe.php

Confirmed by php.net

Did this fix it?

Cause 2 of 4

error_log points at a file the FPM user cannot write

1Check

The manual says the file should be writable by the web server's user. For FPM that is the user set for the pool, not your login. Try to create the file as that user.

sudo -u www-data touch /var/log/php/errors.log
ls -l /var/log/php/

2Fix

Create the folder and file, and hand them to the pool user.

sudo mkdir -p /var/log/php
sudo touch /var/log/php/errors.log
sudo chown www-data:www-data /var/log/php/errors.log

3Verify

The probe's error_log() line lands in the file.

curl -s http://localhost/probe.php
tail -n 3 /var/log/php/errors.log

Confirmed by php.net

Did this fix it?

Cause 3 of 4

A pool setting overrides the php.ini you edited

1Check

FPM pools can pass settings with php_admin_value and php_admin_flag. The manual says those cannot be overridden by ini_set(), and they win over php.ini for that pool. Search the pool files for them.

grep -rn "error_log\|log_errors" /etc/php/8.3/fpm/

2Fix

Change the value in the pool file, or remove the line so php.ini applies.

; pool file, for example www.conf
php_admin_value[error_log] = /var/log/php/errors.log
php_admin_flag[log_errors] = on

3Verify

Restart FPM and rerun the probe; it shows the pool's path.

sudo systemctl restart php8.3-fpm
curl -s http://localhost/probe.php

Confirmed by php.net

Did this fix it?

Cause 4 of 4

Worker output is thrown away

1Check

The manual says that unless catch_workers_output is set, worker stdout and stderr go to /dev/null. Its default is no.

grep -rn "catch_workers_output" /etc/php/8.3/fpm/pool.d/

2Fix

Enable it in the pool file. FPM then copies worker output into its main error log.

; pool file
catch_workers_output = yes

3Verify

Restart FPM, run a script that writes to stderr, and read the FPM main log; the global error_log setting names it.

sudo systemctl restart php8.3-fpm
grep -rn "^error_log" /etc/php/8.3/fpm/php-fpm.conf

Confirmed by php.net

Did this fix it?

How do I stop it coming back?

  • Set log_errors and a full error_log path on purpose in production instead of relying on defaults.
  • Keep display_errors off in production and read the log instead.
  • After editing any ini file, restart FPM and re-run a probe through FPM, because the CLI reads a different configuration.
  • Create the log file with the pool user as owner when you provision the server.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

CodeIgniter 4 cannot write its cache files

CodeIgniter\Cache\Exceptions\CacheException: Cache unable to write to /var/www/app/writable/cache/

CodeIgniter 4's file cache needs a cache directory that the web server can really write to.

2 causes, each with a fix

Back end

CodeIgniter 3 loads the model but the property is undefined

The model name you are loading is the name of a resource that is already being used: user

CodeIgniter 3 expects a model file named like its class, with the first letter capitalised, for example User_model.php holding class User_model.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.