PHP won’t show any errors, or just a blank page
Getting a white page (the infamous the white page of death) when you instruct your browser to open your website? Want to debug an error, but you don’t see error messages on the screen but you do in your logfiles?
Then you should enable the displaying of errors in PHP.
There are few ways you can do this. But the best (fool proof) way is to have this in your php.ini
file:
; file /etc/php5/apache2/php.ini
; here goes other settings
display_errors = On
NB: Don’t forget to restart your webserver after changing PHP’s configuration for it to have effect: sudo service apache2 restart
More comprehensive options
If you want, you can enhance or broaden the displaying of error messages with the following.
There are a few options you can tweak:
- error_reporting (integer) – Set the reporting level. Can be an integer or predefined constant like E_ALL
- display_errors (string) – whether errors should be printed to the screen as part of the output
- display_startup_errors (boolean) – direct from the manual: Even when display_errors is on, errors that occur during PHP’s startup sequence are not displayed. It’s strongly recommended to keep display_startup_errors off, except for debugging.
- log_errors (boolean) – Whether error should be logged to the server’s error log
- track_errors (boolean) – If enabled, the last error message will always be present in the variable $php_errormsg
- html_errors (boolean) – if enabled, error messages will include HTML tags. It will contain clickable messages that direct the user to a page describin the error or function in causing the error.
- error levels: E_ALL ( see for a full list the php.net page of Predifined Constants)
- see for a full list the run-time configuration documentation
The dangers of using ini_set in your PHP page for error displaying
Watch it! If you use ini_set(‘display_errors’, ‘on’);
on your PHP page, then you might miss out.
What happens if a parsing-error occurs on the page that you put this ini-setting on? It would not get parsed so the ini-setting would not be set. So your errors still won’t be displayed.
Oops! So make sure you enable errors in your php.ini
or .htaccess
file instead of your PHP files.