What is a HTTP 500 error?

What is a HTTP 500 error? How can you easily solve a 500 error in your website?

What is a HTTP 500 error?

What is a 500 internal server error?

A 500 internal server error indicates that your website currently has an error and cannot be loaded. In this case it often means that there is a problem in a script that the website needs to display.

The server where your website is hosted executes the scripts you have made and expects the result to be passed on to your browser. Your browser then displays the result and in most cases that is your website. If, for example, there is a typo in your script, the server cannot execute the script and therefore your browser cannot display the website. The server realizes that it cannot show a result to your browser and catches it with a server error. In this case, your browser displays an internal server error with a certain status code, for example 500. This is also called an HTTP status code.

All server error http status codes

  • 500: Internal Server Error
  • 501: Not Implemented
  • 502: Bad Gateway
  • 503: Service not available
  • 504: Gateway Timeout
  • 505: HTTP Version Not Supported
  • 509: Bandwidth exceeded (unofficial HTTP status code)
  • 510: Not renewed
  • 511: Network Authentication Required
  • 521: Web server is down (Cloudflare only)
  • 522: Connection taking too long (Only at Cloudflare)
  • 523: Source is unreachable (Only at Cloudflare)
  • 525: SSL handshake fails (Only at Cloudflare)

How do I solve a 500 internal server error?

Solve 500 internal server error in 3 steps

  1. View the log file
  2. Open the file containing the error
  3. Fixing the error

View the log file

First of all, it is important to know what the exact problem is, what caused the problem and in which file the problem is located.

This is a file where all requests, warnings and errors are written to.

Often the requests are in the file called access.log or access_log. The warnings and errors are often in the error.log or error_log. There will undoubtedly be several variants of the log name, but often the title will contain the subject you are looking for!

In this article I have listed an error in a php script as an example from our log below:

Mon Aug 04 12:51:07.885464 2016] [lsapi:error] [pid 89667:tid 139625036830464] [client 89.205.137.188:38415] [host 1.2.3.4] Backend fatal error: PHP Parse error: syntax error, unexpected end of file, expecting variable (T_VARIABLE) or ${ (T_DOLLAR_OPEN_CURLY_BRACES) or {$ (T_CURLY_OPEN)) in /var/www/html/phpinfo.php on line 2.

This log line tells us that something is wrong in the file /var/www/html/phpinfo.php on line number 4. Here you could possibly find the error that causes you to get the http 500 error when surfing to your domain name .

Open file with error

In this step, we’re going to open the file we just found, namely /var/www/html/phpinfo.php and see what it says on line number 2.

My example .php script

<?php
echo "hello world';
?>

Now that I have opened the file, I can actually see the error that occurs quite quickly.

You see that I use the function echo to print the text “hello world” on the screen. This echo function requires you to enclose the text in double quotes, but as you can see I open the function with double quotes, but close it with single quotes.

Fixing the Error

Now that I’ve found the error, I’m going to modify the script and fix the error. So I modify the php script to the following script:

<?php
echo "hello world";
?>

I save the script and visit the domain name where I uploaded my script. If all went well, you should now see the text : “hello world” appear on the screen and you do not have a new line in your log file.

This means that you solved your http 500 error all by yourself and your website should be fully functional again!

Wordpress 500 internal server error?

Since WordPress is the most widely used CMS worldwide, an HTTP 500 error is also often found here (unfortunately).

Fortunately, because there are so many WordPress websites online and created, there is also a lot to find about the 500 errors and you can often quite easily apply a solution to your WordPress website.

To help you out, I’ve put together a few steps that you should always try first before looking further on the internet or within your website.

WordPress 500 internal server fix in a few steps!

  1. Look at the logs Review the logs as already described above and see in them if you can figure out an error message, or a file/plugin/theme that is known to you.
  2. Disable the theme or plugin Once you have found the error - often in a theme or a plugin - disable this theme or plugin. If you can still do this via the WordPress backend, I recommend doing it there. If that doesn’t work anymore, then the FTP is the place to change the folder of the theme or plugin to, for example, theme-name-old. This will prevent WordPress from finding the theme or plugin and disable it.
  3. Check that WordPress website no longer has a http 500 error Once you have done this, visit your WordPress website and check if it works again. Should the errors be gone, then you have solved it. If there are still errors, check the log again and check if the error message has changed. Possibly there is something else wrong and you can solve it by disabling the theme or plugin as well!

Sometimes it also pays to google the exact error message from the logs of your website that you checked in step 1.

For example, the error may be known on the Internet and you can easily fix it via an update or modification to the theme or plugin!

Just keep in mind that you always try to find out where the error / problem is first and only then start looking for a solution!

Categories

domain webhosting php apache error