Preventing the White Screen in Drupal

If you are using Drupal on share hosting, you have probably experienced a white screen. You see nothing on the screen. You had might as well be skiing in a blizzard. This generally happens when PHP runs out of memory and is one of the biggest problems with shared hosting.

But do not panic. It is fairly easy to fix in most cases.

Modules

The dreaded white screen seems to happen on the module page in the administration section more often then other pages. The reason is that when accessing this page, Drupal loads all of the modules, whether they are active or not. This puts a massive strain on the poor shared hosting server. The obvious answer here is to remove any modules that you do not use. It is not good enough to simply deactivate them. You must delete them off the server. You can do this by using your ftp programme, navigate to the module folder, select the modules you are not using and hit delete. Make sure you have de-activated them in the module screen first.

Increasing PHP memory

Increasing available memory is the second stage in preventing the white screen. Normally this is done in the php.ini file, but on most shared hosting packages, you do not have access to php.ini. Fortunately you can, in most cases, increase the memory in the .htaccess file. The .htaccess is installed automatically when you first install Drupal, so you do not need to create a new one.

Add the following line to your .htaccess file:

php_value memory_limit 20M

Add it three times, under # PHP 4, Apache 1, # PHP 4, Apache 2 and # PHP 5, Apache 1 and 2 if you do not know which version of PHP and Apache you are running. So the .htaccess file will look like this:

# PHP 4, Apache 1.

php_value magic_quotes_gpc 0
php_value register_globals 0
php_value session.auto_start 0
php_value mbstring.http_input pass
php_value mbstring.http_output pass
php_value mbstring.encoding_translation 0
php_value memory_limit 20M

# PHP 4, Apache 2.

php_value magic_quotes_gpc 0
php_value register_globals 0
php_value session.auto_start 0
php_value mbstring.http_input pass
php_value mbstring.http_output pass
php_value mbstring.encoding_translation 0
php_value memory_limit 20M

# PHP 5, Apache 1 and 2.

php_value magic_quotes_gpc 0
php_value register_globals 0
php_value session.auto_start 0
php_value mbstring.http_input pass
php_value mbstring.http_output pass
php_value mbstring.encoding_translation 0
php_value memory_limit 20M

You can get away with a limit of 12M most of the time, but if you have a site with a lot of modules installed, then 20M is recommended.

Error reporting

If you are still getting the white screen after completing the first two steps, then it could be because your error reporting is turned off and the issue is not a memory problem.

In order to see errors on the screen, add the following code at the top of the index.php file (in the root directory):

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

/**
* @file
*/

Make sure you add the code inside the <?php tags

Can not access the website

Sometimes your site will crash completely before you get a chance to complete the above stages. You might be presented with a screen full of errors on every page of the site.

This is normally caused by too many modules installed for the available memory. You need to temporarily deactivate the last module (s) that you installed before the problem occurred.

But how do you do this if you can not access the site you ask?! Easy!

Go to phpMyadmin and find the system table. Then find the last module(s) that you installed and click edit. Change the status to 0. That will deactivate the module and give you a chance to fix the memory problems.

If you liked this, you'll love my book, Master Drupal Module Development.

"..the must have drupal developers book"


Feeling stuck with Drupal 8 module dev?

Get the free 7 lesson course that will help you get started today without feeling overwhelmed.

  • Create Drupal modules with just a few commands using the Drupal Console
  • Create custom pages
  • Create custom blocks
  • Create admin forms
  • Demystify routers and controllers
  • Bonus material

Find out more


Comments

This was the most comprehensible article about the white screen of death problem that i read so far.

This is another article that i found helpful:

http://www.ubercart.org/faq/2246

It also mentions how to set the memory limit in the settings.php file.

Thank you for your efforts!

sdk

This was really useful, pointing out module overload on shared hosting all the way down to Changing the module in PHPMyAdmin to 0. Nicely done!

Clear cut writing and detailed instruction for even the novice to understand. Awesome. Thank you. Because of Drupal WSOD i moved to using wordpress. But now my confidence is back to drupal.
Thank you

Add new comment