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 error_log setting in the PHP configuration file (php.ini) is not properly configured or is pointing to a non-existent file. Make sure that the error_log setting is set to a valid file path, and that the file has the proper permissions to be written to.

Watch a course Learn object oriented PHP

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:

php -i | grep error_reporting

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

error_reporting(E_ALL);

This will cause all errors to be reported.

It is also possible that the errors are being sent to the standard error output (STDERR) instead of the standard output (STDOUT). 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 solution works, please check your PHP version and configurations, it might be that your CLI version is different than the one used by your web server.