When you have a website regardless if it’s a php only site or a WordPress site you have probably encountered the 500 Internal Server Error.

The server shows the error but doesn’t tell you anything that may have caused it.

Another type of bad error is to not see an error at all but a blank page.

I know you’re busy and want to do some awesome work but this issue has to be resolved first.

Take a deep breath and read on.

What is 500 Internal Server Error?

This is one of the most common server errors. It occurs when there’s some sort of an issue with the server. It’s called a server-side error. This means It’s computer or your Internet connection but it may or may not be caused by your WordPress site.

The error is pretty generic and in order to find the cause some troubleshooting has to be done which might take several hours to fix. The most important thing is to find the cause of that error. Then the next step is to come up with a solution.

Troubleshooting

The first thing is to ask yourself when the Internal Server Error started happening.

With computers and sites things do not happen by themselves. Something or someone did something and as a result something else happened. 

The first step is to check the logs. There should be a specific error message which part of the site had caused the error.

If you have a control panel do search for log and navigate to them

If your site is running nginx web server the logs are usually saved here:

/var/log/nginx/error.log

If your site is running the apache web server the logs are usually saved here:

/var/log/apache2/error.log

For the last 2 folders you may need root/admin and ssh access.

You can always ask the support to check your site and/or if they don’t want to fix it for you, maybe they can at least give you the last 100 lines of those lgo files.

When you have a specific error message or a problem that has caused 500 Internal Server Error you can google it and see what other people have done to resolve it.

Backup!

Before you do anything on your site always take a fresh backup. Do not rely on the hosting's backups as they may be outdated.

Always take 2-3 backups using different approaches to ensure the backup is good and you can actually restore from it.

What are the most common reasons causing 500 Internal Server Error?

  • cgi-scripts
  • errors in .htaccess
  • php script or a WordPress plugin/theme exceeded memory usage
  • php code or WordPress plugin/theme is calling an non-existent function
  • PHP Function name collision
  • web hosting issues
  • Resource exhaustion
  • Missing php extension

CGI or Perl scripts

With CGI/perl scripts you must explicitly output the content-type header otherwise you’ll see the  500 Internal Server Error.

You can do this by doing the following.

print "Content-type:text/html\n\n";

Another reason might be that a specific Perl module or library wasn’t loaded but was referenced.

If you're running WordPress you probably are not using Perl.

Errors in .htaccess

If you’ve manually edited the .htaccess file and inserted an extra character or maybe a plugin did some modification to that file e.g. a caching plugin had inserted its rules.

The reason could be that extra character that Apache web server doesn’t recognize OR if an apache module isn’t installed or activated.

Solution: Connect via (S)FTP and rename the .htaccess to .htaccess-000. 

It’s good to append some text to the file name but keep the prefix because servers are configured to block access to files that start with .ht and that’s a good thing. You don’t want somebody else checking what rules you have. They should not pose any security risk but you never know. The attackers should get no or very little information about the system.

then reload the site and see if you’re still seeing 500 Internal Server Error.

If you still are seeing that error that means that it’s not the .htaccess file and you should rename it back to its original name.

PHP Memory Limit

Scripts need some memory to operate and store data. Sometimes PHP or WordPress needs more memory to complete a request. This could be the case when data is pulled from the database or if there’s heavy image processing especially if the image is large and uploaded straight from the phone and without an optimization. 

By the way did you know that you can use Static Optimizer to optimize your images for free?

If you have access to the php.ini file you can try setting the php memory limit to 128MB first.

memory_limit=128M

You need to reload the page and then if the internal error still persists then increase it to 256MB.

memory_limit=256M

That should be fine in most cases. If it still doesn’t work then increase it to 512MB.

memory_limit=512M

Important Note: Keep in mind that the limit value should end in M and not MB.

Also your server has to have enough memory to handle or its memory would get full and the operating system will start stopping services such as the web server or the database.

If you do not have access to the php.ini file You can try adding the values as php constant that WordPress will try to use in your wp-config.php file. Then reload the page again.

define('WP_MEMORY_LIMIT', '256M');

You can also try to increase the php memory limit by adding this code block to your .htaccess file.
It does have a check because it would only work if php is installed as an apache module. Having that check should not cause the site to trigger yet another Internal Server Error.

<IfModule mod_php7.c>
	php_value memory_limit 256M
</IfModule>

Calling a missing or not loaded PHP function

Yes, yet another reason to see the 500 error. Sometimes WordPress designers call a plugin from a plugin expecting that it will always be available and in reality it’s not.

For this reason it’s good to have some checks in the theme if a function exists at all before calling it. Yes, some content will be missing but the site won’t crash or show the internal server error message.

To find out if a php missing php function is to blame for the error you need t o enable WordPress debugging and to check the debug.log file. Then scroll to the end of the file and look for a PHP fatal error message. Because php doesn’t know how to continue, it crashes.

PHP Function name collision

This happens very often because when a file is loaded twice and a function is already defined. This also causes php to crash.

Solution: So use include_once() or require_once()

Another reason is that you have duplicated a file that gets automatically loaded or you forgot to rename the class or function prefixes.

The bottom line is functions and classes have to be unique (within the global namespace).

Otherwise how would php know which one to call?

Another reason if you/plugin or other php code is using a reserved php keyword as a function name such as these ones 

  • list()
  • die()
  • include_once()
  • require_once()

you can read more on the reserved php keywords

You can rename the plugins directory to plugins000. The plugins folder can be found in wp-content/plugins/

The logic here is that when you rename the folder WordPress won't find the plugins and you'll quickly realize if it's a plugin causing the issue. If the error still persists maybe it's related to the theme. You can rename each plugin folder one by one. On average the WordPress sites have between 20-50 plugins so it may take a while to find the plugin.

Another option might be to enable WordPress debugging and keep an eye to the debug.log file which can be found in wp-content/debug.log. Add this to your wp-config.php file right after the opening php tag <?php

Do make sure that there aren't any other lines defining any of the following constants below or they won't take any effect.

We are using a defined() check first so php will attempt to define the php constant only if it's not defined yet.
Otherwise you'll get php notices/warnings.

defined('WP_DEBUG') || define( 'WP_DEBUG', true );
defined('WP_DEBUG_LOG') || define( 'WP_DEBUG_LOG', true );
defined('WP_DEBUG_DISPLAY') || define( 'WP_DEBUG_DISPLAY', true );
defined('WP_DISABLE_FATAL_ERROR_HANDLER') 
	|| define( 'WP_DISABLE_FATAL_ERROR_HANDLER', true );

If you're troubleshooting a live WordPress site you may want to enable the debugging only for yourself with an IP check.

To find your IP address you can type in Google: what's my ip and it will give it to you.
Then add it to the php array below $my_ips. You can keep the trailing comma. PHP will ignore it. It's easier to add new elements to the array that way.

The following IP check may not work if you or your hosting provider have set up multiple servers which are not fully configured.
e.g. reverse proxy which sends the request to another server to complete the request. Apache requires the remoteip module to set the correct IP when it's behind a reverse proxy.

$my_ips = [
	'127.0.0.1',
	'111.222.333.444', // <-- change me
];

if (!empty($_SERVER['SERVER_NAME'])
	&& !empty($_SERVER['REMOTE_ADDR'])
	&& in_array($_SERVER['REMOTE_ADDR'], $my_ips)
) {
	defined('WP_DEBUG') || define( 'WP_DEBUG', true );
	defined('WP_DEBUG_LOG') || define( 'WP_DEBUG_LOG', true );
	defined('WP_DEBUG_DISPLAY') || define( 'WP_DEBUG_DISPLAY', true );
	defined('WP_DISABLE_FATAL_ERROR_HANDLER') 
		|| define( 'WP_DISABLE_FATAL_ERROR_HANDLER', true );
}

web hosting issues

If your site is hosted on a shared WordPress hosting the hosting provider is most likely trying to maximize on their equipment so they can put lots of people on the same server.

That may not sound fair but if the hosting plan is very cheap the hosting provider has to ensure that nobody can consume more resources than they are allocated. This will ensure that all sites on the server can have resources to operate as expected.

Missing php extension

If a php extension is missing that could crash the site.

Maybe your hosting provider has upgraded php and forgot to install or enable a given php extension. It’s good to contact them and let them know about the error.

We know from experience that as software providers we can’t catch all of the errors that a piece of software may have. For this reason we also rely on our customers to let us know if there’s an error so we can troubleshoot and fix it. 

That happened several times with our products: Staging WordPress sites and WPSandbox.net .

We are very thankful for them taking the time to report this.

In our case the issue happened because there’s a big software update and things will not always go according to plan. That’s normal. It could be stressful but there are so many lessons that can be learned in those cases.

In conclusion, the 500 Internal Server Error  is one of the most common and also frustrating errors that can occur in WordPress. Patience is a virtue in this case too.

Take the time to troubleshoot the issue and rule out each option one by one.

Your main goal is to find the root cause of the problem. That means that 80% of the battle is won. The solution in most cases would become obvious after that.


Disclaimer: The content in this post is for educational purposes only. Always remember to take a backup before doing any of the suggested steps just to be on the safe side.
Referral Note: When you purchase through a referral link (if any) on this page, we may earn a commission.
If you're feeling thankful, you can buy me a coffee or a beer