Sometimes it happens that website turns into a “beautiful” white page and nothing in the source code of the HTML generated code can help to find why.
This article is meant to help developers to find the common reasons.
“Invisible” Errors :
If error reporting is turned off fatal errors are not showed up (on production environment for example) and this can be the origin of white page. So it’s important to enable it on developement / testing environments, and you can do this by :
Enabling error reporting :
error_reporting(E_ALL); ini_set('display_errors', TRUE); ini_set('display_startup_errors', TRUE);
Using .htaccess file :
# PHP error handling for development servers php_flag display_startup_errors on php_flag display_errors on php_flag html_errors on php_flag log_errors on
Here you can find a nice article about .htaccess directives to handle errors.
Apache logs :
Also another way to track errors is to look on apache logs. The location of these files depends on what you have configured / apache version / vhosts configs .. etc.
To find apache errors logs phpinfo() can be helpfull, look for variable called : error_log
Or by default (on linux) apache logs are on /var/log/apache2/ directory.
To find errors :
grep -r 'ErrorLog' /var/log/apache2/*
Whitespace at the end of PHP scripts :
This is the common error code that gives WSOD, so one of the best PHP coding practices is to avoid closing php tag (?>) at the end of script.
Infinite loops :
Infinite loops can cause WSOD, but apache can detect this on it will report it on error logs with something like this :
[notice] child pid ##### exit signal Illegal instruction (4)
To sum up it’s important to know where to search, so first of all error reporting must be active to help to find the origin of the problem. On production environments debug can be tricky so you need to have apache logs accessible.