25

How can I see the error messages when the site I am working on gets a white screen?

33

Put this at the bottom of settings.php:

error_reporting(-1);  // Have PHP complain about absolutely everything 
$conf['error_level'] = 2;  // Show all messages on your screen, 2 = ERROR_REPORTING_DISPLAY_ALL.
ini_set('display_errors', TRUE);  // These lines just give you content on WSOD pages.
ini_set('display_startup_errors', TRUE);
  • This is great for development sites though I prefer /var/log/apache2/error.log for live sites. This works though. :) – Citricguy Feb 3 '12 at 5:25
17

The White Screen of Death (Completely Blank Page) resource on drupal.org will step you through the steps to see the error message as well as common problems that cause them.

"Invisible" Errors

If error reporting is turned off, you could be getting a fatal error but not seeing it. On a production site, it is common to have error reporting turned off. If that is the case and PHP has hit an unrecoverable error, neither an error nor content will be displayed, therefore you end up with a completely blank page.

What you can do about this is either turn on PHP error reporting so it displays a message on the page itself, or check your log files (from the server) to look for the error. How to do both of these are explained below.

Enable Error Reporting

Although it may be turned off on commercial hosts and production sites (for good reason, so that users do not see the errors), these errors are one of your best tools for troubleshooting. To enable error reporting, temporarily edit your index.php file (normally located in your root directory) directly after the first opening PHP tag (do not edit the actual file info!) to add the following:

error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);

You will now be able to see any errors that are occurring directly on the screen. Memory problems may still not be displayed, but it's the first step in a process of elimination.

If you are using a multi-site setup and only want errors to appear for one site, then check the name of the host first as in:

if ($_SERVER['HTTP_HOST']==='some.domain.name.here') {
  error_reporting(E_ALL);
  ini_set('display_errors', TRUE);
  ini_set('display_startup_errors', TRUE);
}

If the problem occurs while running update.php open update.php in a text editor and uncomment the following line:

ini_set('display_errors', FALSE);
10

Have a look at Apache error log, in Ubuntu it's located in /var/log/apache2/error.log so you can do:

tail -f /var/log/apache2/error.log
  • 2
    sudo tail -f /var/log/apache2/error.log – Citricguy Feb 3 '12 at 5:23
  • 1
    if you have many vhosts with custom log files for each of them, just use this : sudo tail -f /var/log/apache2/*.log then refresh the page that ends with wsod – izus Jul 15 '16 at 21:19
2

I found easy way of tracking down the WSOD errors by running the whole site via drush, e.g.:

drush rs

After that access the site at the given new address (e.g. 127.0.0.1:8080), then try to reproduce the problem, and you'll see all errors on the terminal screen. No need to reconfiguring your PHP, especially in cases when display_errors fails (e.g. MAMP).


Other tricky way I've found it by using debuggers, e.g.:

  • OS X:

    sudo dtruss -fn httpd 2>&1 | grep -i error
    
  • Linux:

    sudo strace -f $(pgrep -fn httpd) 2>&1 | grep -i error
    

    Note: Change httpd into php if you're using drush rs as above.

Or installing XDebug PHP extension and generate a trace file (xdebug.auto_trace=1).

  • 1
    You sir, are a life saver. None of the changing php settings nonsense worked for me, but this did the trick! – Greg Somers Jun 21 '18 at 3:48
1

If you are using drush, you can see error messages using drush-ws command.

0

I just changed the variable $update_free_access value from FALSE to TRUE and executed the update.php file. It resolved my problem.

0

You can modify index.php and wrap up the code with a try / catch. Like this:

try {
    define('DRUPAL_ROOT', getcwd());
    require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
    drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
    menu_execute_active_handler();
} catch (Error $t) {
    error_log('Error at Line:' . $t->getLine() . ' File: ' . $t->getFile() . ' Message:' . $t->getMessage() );
    print '<div>Message: ' . $t->getMessage() . '</div>';
    print '<div>File:' . $t->getFile() . '</div>';
    print '<div>Line:' . $t->getLine() . '</div>';
}

The Error message will show the file and line of code which caused the error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.