How to fix Drupal 500 internal server error – Top 7 causes & solutions

How to fix Drupal 500 internal server error
How to fix Drupal 500 internal server error – Top 7 causes & solutions

Is your Drupal site showing “500 Internal Server Error” all of a sudden?

In our role as Support Engineers for web hosts, this is a common error we see in Drupal websites.

We’ve seen this happen during:

  • Drupal core update,
  • Module or Theme update,
  • Website feature additions (code update),
  • PHP upgrade or reconfiguration,
  • Web server (eg. Apache) updates,
  • Website migration, or
  • New website setup

What is Drupal 500 internal server error?

500 Internal Server Error is a web server’s way of saying, “Something has gone wrong when I tried to display the page. Not sure what.

Almost always it means that there is a configuration error in either the web server settings, PHP settings or website settings.

Some of these errors are temporary (eg. due to resource limits), and might go away when you refresh the site.

But if it doesn’t, it might indeed be a server issue.

How to troubleshoot Drupal error 500

The standard way to troubleshoot error 500 is to analyze the web server log files.

An error log might look something like this:

[Thu Jul 19 11:01:33.126782 2018] [:error] [pid 31931] [client xx.xx.xx.xx] PHP Fatal error: Allowed memory size of 1048576 bytes exhausted (tried to allocate 17120 bytes) in /var/www/drupal7/includes/module.inc on line 503

It won’t make much sense if you aren’t a developer.

So, let’s see what else can be done.

Troubleshooting using error display in Drupal

All web hosts supress PHP errors by default.

So, when there’s an Error 500, you’re not likely to see the reason on the site.

However, you can enable error reporting by adding these lines in index.php.

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

And when the page is refreshed, you may see an error such as this:

PHP Fatal error: require_once(): Failed opening required '/home/username/sitename/docroot/sites/all/modules/contrib/rules_dev_comments/includes/rules_dev_comments.plugin.inc' (include_path='.:/usr/share/php:/usr/share/pear') in /home/username/sitename/docroot/includes/bootstrap.inc on line 3157

Again, that one can also be a bit difficult to understand if you aren’t a Drupal developer.

Drupal error 500 troubleshooting for humans

For those who do not want a PhD in Drupal, and wants this error fixed, we’ll list here the most common causes for this error, and how to fix them.

1. Misconfigured .htaccess

The number one reason we’ve seen for this error is incompatibility of .htaccess settings with the server environment.

Some hosting accounts will be set to single site environment, while others will be set to multi-site.

Some will allow directory listing and soft links, while others may not.

But Drupal packages and installation instructions assume a basic set of hosting settings to be present.

We’ve seen enabling or disabling these settings (differs from one server to another) can fix this error:

RewriteBase /
Options -Multiviews
Options +FollowSymLinks
Options -Indexes

Comment (by adding a #) or uncomment these settings one by one to see if it’ll clear the error.

If it is an error with .htaccess, that should fix it.

2. PHP configuration errors

The next big source of error is PHP config issues.

We’ve seen this range from un-installed PHP extensions & wrong PHP paths to incorrect PHP.ini & obsolete PHP handlers.

By default, Drupal requires these PHP extensions to function, but misconfigurations can prevent access to these libraries.

  • OpenSSL
  • Curl
  • GD
  • PDO
  • XML
  • JSON
  • Mbstring

In addition to these modules, PHP also requires certain PHP settings to be set right.

For eg. “allow_url_fopen”, “magic_quotes_gpc”, and “register_globals” needs to be set to “off”.

We’ve seen cases where this is either not set right, or the website uses an incorrect version of php.ini, that had the settings configured wrong.

To fix this, we use a two step method:

  • Verify PHP config path – We check if the PHP handler, PHP program file, and the PHP configuration file are all set correctly.
  • Verify PHP settings – We then look at the settings to make sure everything is as per Drupal’s requirement doc.

The list of individual specs are a bit too long for this article. However, if you need help fixing your site, click here to talk to our Drupal experts.

3. Resource limits

In VPS and Shared hosting servers, a big cause of errors is the memory limit.

Drupal core only requires 32 MB of memory to execute, and most hosting accounts provide a minimum of 128 MB or 256 MB of memory for Drupal processes.

However, when modules are added, the memory requirement of Drupal processes can exceed the allocated quota. The operating system will kill such processes, and the visitor gets a 500 error.

Here’s one way that we’ve seen to be working for many:

  • Login to your FTP account.
  • Download .htaccess file.
  • Add the line php_value memory_limit 512M in the file, and save
  • Re-upload the file.

If you are not sure how to do this, or if editing is disallowed in your account, our Prestashop experts can help you fix this. Click here to submit a support request. We are online 24/7.

4. File ownership or permission errors

Site migrations or new site setup can be hard.

A lot of settings need to be changed to make an app compatible to the new environment.

We’ve seen file and folder permissions set wrong in Drupal installations, causing the PHP execution to fail.

The right permissions for files is 644 and folders is 755.

If you see anywhere in the log files that the permissions (user, group, world) is not set right, these commands could help:

find /home/USERNAME/public_html -type d -exec chmod 755 {} \;
find /home/USERNAME/public_html -type f -exec chmod 644 {} \;

Replace /home/USERNAME/public_html with the path to your web directory.

You might also do this from an admin front-end (if you are provided with one).

Warning : Take a backup of your site before you execute any command.

5. Errors in Drupal modules or themes

Not all modules are created equal.

Some have code errors, like a missing “;” or a wrong module path.

We’ve seen Drupal sites go down after an upgrade, or a code update, or a backup restore.

In such cases, you can disable the Drupal modules and themes one by one to find out which one caused the error.

A faster way is to analyze the log files and figure out the error’s origin. Here at Bobcares, that’s our favored method, and helps us resolve issues within minutes.

6. Web server or FastCGI config issues

Many settings in webservers can conflict with each other.

For eg. since Apache 2.2, the config option “SymLinksIfOwnerMatch” is available that is more secure than the older “FollowSymLinks”.

We’ve seen sites where both these options are enabled in .htaccess, causing the site to fail.

This usually happens after a migration where the site owner tries to retain the old settings while adding the new ones.

Similarly, FastCGI has many limits such as Process Execution Time, Request Length, etc. which we’ve found to limit Drupal execution.

In such cases, there are no cookie-cutter solutions. We follow the log trail, find out what the conflicts are, and fix the offending setting.

7. Stale cache, security settings, and others

Temporary issues like resource bottlenecks or server load can cause Drupal error 500.

But the Drupal or server cache will store them for a while more even after the error has passed.

So, in many cases, we’ve solved the issue just by clearing the cache.

Similarly, we’ve seen this error displayed when a script execution is blocked by a firewall such as mod_security.

In such cases, we identify which exact security rule is being triggered and add an exemption for that site.

More causes for Drupal error 500

There can be way more reasons such as Database errors, Brute force attacks, etc. for this error to happen.

Conclusion

Drupal 500 internal server error is caused by resource limits, PHP misconfiguration, .htaccess errors, and more.

Scroll to Top