Skip to content

PHP CLI won't log errors

There are a few things that can cause errors to not be logged when running PHP from the command line interface (CLI). One common issue is that the log_errors setting in the PHP configuration file (php.ini) is not enabled, or the error_log setting is pointing to a non-existent file. First, verify which configuration file the CLI is actually loading by running php --ini. Make sure that log_errors = On is set, and that the error_log path is valid and writable.

Another potential issue is that the error reporting level is not set to include the types of errors you are experiencing. You can check the current error reporting level by running the following command:

Example of checking the current error reporting level in PHP CLI

php
php -i | grep error_reporting

You can also set the error reporting level by adding the following line to your PHP script:

Example of setting the current error reporting level in PHP CLI

php
error_reporting(E_ALL);

This will cause all errors to be reported for the current script runtime.

It is also possible that the errors are being sent to the standard error output (STDERR) instead of the standard output (STDOUT). By default, display_errors is set to On in the CLI, which prints errors directly to the screen rather than logging them. If this is the case, you can redirect STDERR to a file by appending `2> error_log.txt` to the end of your PHP command.

If none of the above solutions work, please check your PHP version and configurations; it might be that your CLI version is different from the one used by your web server.

Dual-run preview — compare with live Symfony routes.