How to fix HTTP error 500?

HTTP status codes tell you whether an online request was successful and, if not, what went wrong. But the error messages aren’t always clear. This is especially true of the “500 Internal Server Error.” This message means that an error occurred on the server and the requested page cannot be accessed. However, it doesn’t tell you why. Fortunately, there are several ways to find the cause. Below, we list typical error sources and explain what to do if you encounter HTTP error 500.
What does the internal server error mean?
Using status codes, the web server tells an internet user’s browser (client) whether a request (i.e. accessing a website) was successful or not. If the browser receives the 200 status code, it knows that everything went well. The user never sees this code, because the requested content appears instead. The situation is different with the 400 and 500 status codes. The former indicate client errors; the latter are server-related. Internal Server Error 500 is a collective status code for server errors, so at first glance you cannot tell where the error actually lies. The user only knows that the server has reported an unexpected error.
However, if the server runs Microsoft Internet Information Services (Microsoft IIS), the error code is more specific. The decimal places describe the cause of the error in more detail:
- 500.0: Module or ISAPI error occurred.
- 500.11: Application is shutting down on the web server.
- 500.12: Application is busy restarting on the web server.
- 500.13: Web server is too busy.
- 500.15: Direct requests for global.asax are not allowed.
- 500.19: Configuration data is invalid.
- 500.21: Module not recognized.
- 500.22: An ASP.NET httpModules configuration does not apply in Managed Pipeline mode.
- 500.23: An ASP.NET httpHandlers configuration does not apply in Managed Pipeline mode.
- 500.24: An ASP.NET impersonation configuration does not apply in Managed Pipeline mode.
- 500.50: A rewrite error occurred during RQ_BEGIN_REQUEST notification handling. A configuration or inbound rule execution error occurred.
- 500.51: A rewrite error occurred during GL_PRE_BEGIN_REQUEST notification handling. A global configuration or global rule execution error occurred.
- 500.52: A rewrite error occurred during RQ_SEND_RESPONSE notification handling. An outbound rule execution error occurred.
- 500.53: A rewrite error occurred during RQ_RELEASE_REQUEST_STATE notification handling. An outbound rule execution error occurred. The rule is configured to be executed before the output user cache gets updated.
- 500.100: Internal ASP error.
What are the causes of error 500?
The “Internal Server Error” can occur while the web server is processing the request. This collective status code covers anything unplanned that happens on the server and prevents the website from loading. Most often, the cause is an error in the web server’s configuration. Here are some typical error sources:
- Permission error: The permissions of the main files and folders are not set correctly.
- PHP timeout: The script tries to access an external resource and times out.
- Incorrect code in .htaccess: The structure of a .htaccess file could be wrong.
- Error in syntax or code in CGI/Perl scripts: Some scripts contain errors; paths in particular may be wrong.
- PHP memory limit: A process exceeds the available memory and therefore cannot run correctly.
On WordPress sites or other content management systems, a faulty or incompatible extension can also be the cause. Plugins and themes, especially from third-party providers, can affect the entire website.
How can website operators fix the 500 Internal Server Error?
Are your website visitors seeing only the 500 server error? As the operator, you should fix the problem quickly: it will scare off your visitors, and it could also lead Google to lower your ranking. Before you take action, check whether your server is still running. If it is not, contact your hosting provider as soon as possible.
If there is an internal error, start by viewing the log files. On Linux servers, you should find the collected error messages at /var/log/httpd/error_log. Reload the website to reproduce the HTTP error 500 and watch what is written to the log file. This will usually lead you to the source of the error quickly. Also consider which changes were made shortly before the error appeared. In many cases, badly programmed or incompatible plugins are the cause.
Errors can also occur if permissions for important files are set incorrectly. In general, there are three types of rights:
- Read (r)
- Write (w)
- Execute (x)
These permissions can be assigned to three different user types:
- Owner of the file
- Group of users
- All others
The rights are written either as the letters r, w and x, or as numerical values: 4 for read, 2 for write and 1 for execute. The values are added up for each user type and written one after the other: rwxr-xr-x (rwx for the owner, r-x for the group and r-x for all others), or 755. This configuration (755) should be the default setting. If permissions are set differently, an error may occur. You can change them with this command:
- chmod 755 filename
If this change does not solve the problem, you can temporarily grant all rights to every user type for testing:
- chmod 777 filename
Use this setting only to locate the problem. It allows any user to rewrite the file, which is a clear security risk.
If the permissions were not the cause, check next whether your scripts run correctly. Sometimes errors occur because script files have been moved, renamed or deleted. Also check the .htaccess file: even a small syntax error can cause an internal server error. Incorrect formatting of the .htaccess file is an equally common problem. The file must be created in ASCII or ANSI format, not in Unicode. Write it in a text editor such as Notepad, Notepad++ or Sublime Text, not in a word processor such as Microsoft Word. To test whether the file is responsible for the error, temporarily rename it and reload the website. The server will then skip .htaccess when loading the site. If the error message disappears, repair the file or create a new one.
A timeout can also lead to an error message. In this case, the problem is not the web server itself but an interrupted connection to an external source. Do PHP scripts on your website access resources on other servers? The resource may no longer be available, or communication between the servers may be down for another reason. One way to remove this source of error is to not make your site depend on external resources. If that is not possible, you can increase your script’s time limit. It also helps to implement proper error handling, so that errors in the PHP script can be identified more accurately.
Could the memory be overloaded? The memory limit sets how much memory a process may use. If a process needs more RAM than is available, the result can be an internal server error. As a temporary solution, you can raise the limit by adding a line like this to php.ini:
- memory_limit = 512M
In this example, you set the available memory to 512MB. Note, however, that your hosting provider allows only a certain PHP script limit within the package you have booked. If you enter a higher value, the web server will ignore it. Raising the limit is only a temporary fix: once your site is running again, look for the reason behind the high RAM usage. Most likely, the error lies in your website’s code.
If none of these methods solves the problem, contact your hosting provider. Before you do, check the status of the servers: many hosting providers report server status on a status page or inform users via social media when a problem occurs. AVANETCO customers can open a ticket with our free 24/7 technical support.