Troubleshooting PHP Not Reporting Errors

You've enabled PHP error reporting so that you may troubleshoot PHP code, but for some reason, no errors are being reported. Why?

On the phpinfo.php page, you see the following local values, which are correct:

display_errors On
display_startup_errors On
error_log php_error.log
error_reporting E_ALL

To diagnose the issue, let's create a test script called test.php and add the following lines:

<?php
echo zzzzzxzzzzxd('test');
?>

Since the faked function zzzzzxzzzzxd doesn't exit at all, visiting http://youdomain.com/test.php should trigger a fatal error. However, there is no output of any error on the web browser, nor on the local VirtualHost PHP error logs. Why not?

Check phpinfo.php again. We see error_log's global value is 32767, while the local value is E_ALL. Check the global php.ini and you will find that error_reporting is set to E_ALL. This is because you have a local override set in .htaccess as php_value error_reporting E_ALL.

The error reporting syntax in the .htaccess php_value override is incorrect. If it is set in php.ini, it should be error_reporting = E_ALL, but if it is an override in the Apache conf or .htaccess, error_reporting should be an integer, and not ASCII characters. Such incorrect syntax will lead to a 500 error for the site.

The corrrect override syntax should be:

php_value error_reporting 32767

Here 32767 in Apache conf or .htaccess is equivalent to E_ALL in php.ini. After the above change, PHP error reporting should work fine and PHP should report a fatal error for test.php in both the browser and the error log.

  • Admin
  • Last modified: 2019/07/29 16:25
  • by Lisa Clarke