Status Code 500: Causes and Fixes


An HTTP 500 internal server error is one of the HTTP status codes, just like 301 Moved Permanently or 400 Bad Request. A server sends such codes every time after opening a new page or following a link.

What does internal server error mean? An error 500 is a direct sign that something went wrong and the server couldn’t fulfill the request due to some problem. In this article, we’ll look closely at the most common case scenarios and how to fix them.

The Causes of Status Code 500

As you may already know, a 500 server error is a bird’s-eye message that pops up when something does not work as expected. This generalized answer is used because a thousand different things can cause a server to break, and it’s impossible to provide a separate page for each case.

Status Code 500
Status Code 500

The easiest way to check the cause is to look in the server logs. Nevertheless, here are a few common conditions that trigger an internal server error 500:

  • PHP script error
  • database problems
  • incorrect PHP parameters
  • incorrect access rights to folders and files
  • the site conflicts with a template or extension
  • the system file of the site engine is missing or damaged
  • an error in the global configuration file of the web server
  • an error in the additional configuration file of the web server
  • one of the files has a link to another file, but this file itself is missing
  • the script is not executed due to too low max_execution_time and memory_limit values

How Status Code 500 Affects SEO

If your site got an error 500 internal server error, you should fix it as soon as possible since the site risks getting excluded from the search results. After a web crawler visits your site and sees an HTTP status code 500, it revisits it again within a day to check whether the problem is fixed. However, if the web crawler spots a response code 500 again on the second visit, it might exclude your website from the index.

You can check the index status of your website in Google Search Console. To do so, enter the console, enter your page’s URL in the search bar, and press Enter. The service will check the page and show its status. If the page is no longer in the index, click Request Indexing to re-index it.

Status Code 500 in GSC

The Fixes of Status Code 500

How to fix 500 internal server error? If you have encountered an HTTP 500 internal server error as a user, your only solution is described in the first tip. For the rest of the cases, you will need access to hosting.

The following tips describe the most common error 500 case scenarios. If none of them help you, the wrap-up of this article will hint at your next step.

#1 Clear the cache & refresh the page

A 500 error message might be occasional and disappear after you reload the page. However, the error might get cached, so the cache should be cleared just in case. Here are the guides for each major browser:

#2 Check the logs

This way, you will immediately find the cause (instead of going through all the possible options). If you are not tech-savvy, try the other options first (listed below). You can always get back to this tip in case something goes wrong.

Depending on which web server you are hosting, by default, logs will be stored in the following paths:

  • /var/log/httpd/error_log или /var/log/apache2/error_logfor Apache
  • /var/log/nginx/error_logfor Nginx

Keep in mind that logs can be stored in other places as well. Hosting control panels often change the default path of their location.

Also, shared logs access will only be on VPS hosting or a dedicated server. Shared hosting has its own error_log file. By default, it’s created in the same folder as the script, which resulted in the fact that the request failed with status code 500. But different content management systems can redefine the path to this file for other folders.

Besides, only PHP errors get into this file. Web server errors will get into the main logs, which will not be accessed. So if you are on shared hosting and your PHP error logs are empty, contact your ISP support and ask them to look at the main logs. You need the main logs’ last lines.

#3 Check global config files

If you use shared hosting, there is nothing to worry about. Your hosting provider is responsible for configuring these files, so the probability of an error due to config files tends to be zero.

On the contrary, if you use a VPS or a dedicated server, the responsibility for setting up these files lies on you. In this case, a 500 HTTP status code can be caused by an accidental typo or conflicting directives.

An Apache web server has configuration files in the following locations:

  • The main configuration file httpd.conf in the /etc/httpd/conf/ directory or apache.conf in the /etc/apache2/conf/ directory
  • Additional configuration files hosting virtual hosts in /etc/httpd/conf.d/, /etc/apache2/conf.d/, /etc/apache2/sites-available/ or /etc/apache2/sites-enabled/ directories

An Nginx web server has configuration files in the following locations:

  • The main nginx.conf configuration file in the /etc/nginx/ directory
  • Additional configuration files that host virtual hosts in the /etc/nginx/conf.d/, /etc/nginx/sites-available/ or /etc/nginx/sites-enabled/ directories

The configuration files may be stored in other folders if you manage the server using a control panel. For example, for Webuzo, it is /usr/local/apps/apache, and for Plesk, it is /home/user/conf/.

#4 Check .htaccess config file

This file will be in the domain root folder on any hosting with an Apache web server. Even if you have never edited it, the file may still have an error. For example, this happens with WordPress-based sites: installed plugins add the necessary directives to the file, which sometimes causes conflicts with previous directives. It respectively triggers an HTTP status 500 – internal server error.

To check if the .htaccess is really the issue, rename it on the host and visit the site again. The file will not work with a different name. If the error disappears, the problem is with the file. The only thing left is to find the directive that causes the error. To do so, add a hashtag at the beginning of each directive line:

#RewriteEngine On
#RewriteCond %{HTTP_HOST} !^www\.
#RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

#5 Check folder and file permissions

A web server may lack access to some folders or files, which leads to a status code 500. It simply blocks script execution. Maybe the file (or folder) is invalid, or it has one owner with permission, but the web server executes processes on behalf of another without permission.

How to fix error 500? You can set permissions using FTP clients like FileZilla or using the file manager in the hosting control panel. Here’s how to do it in cPanel:

  • On the panel’s main page, find the “Files” option and go to the “File Manager” section.
  • Select the needed file or folder and click the “Permissions” button in the top panel.
  • Default values that everything should work with: for directories – 755; for files – 644.

#6 Check the database

An internal server error 500 also occurs when the server cannot connect to the database. In this case, the error text will be “Error establishing a database connection,” but the logs will show an error 500.

Most often, the server cannot connect to the database because the database details file contains an incorrect username or password. It happens when you or your programmer make changes but accidentally forget to update them in the file. This file is usually located in the root folder of your site and has the word config in its name. For example, for WordPress sites, it’s wp-config.php, and for OpenCart sites – config.php.

A response code 500 might also be triggered because the MySQL server is overloaded due to a large number of visitors. This often happens on shared hosting, where the number of simultaneous connections to the database is limited for each user.

The number of queries to the database may increase as the traffic to the site grows naturally. As a rule, it means one of two things – either you need more powerful hosting, or the requests are malicious, and you just need to fight them off. You can check the load using the SHOW GLOBAL STATUS, VMSTAT, or TOP commands. Alternatively, you can simply contact the site developer or your hosting provider support for help.

Database corruption can also cause an internal server error. As you fill your site with content, install themes and plugins, and optimize with different tools, something important can be accidentally deleted, which is why the database will stop working. In this case, the solution is to restore the backup (if available).

#7 Check resource usage on the server

Any action on a site starts a process on a server. Expect a queue if there are too many of them and all resources are occupied. This queue can eventually become too long, and new processes will crowd out the old ones. As a result, some important processes may fail, triggering a problem with network 500.

How to fix HTTP error 500? If you use shared hosting, you cannot manage processes – this is the provider’s task. But you may be able to estimate the server load in your control panel. In cPanel, it can be done in the “Statistics” located on the right of the panel’s main page.

In case the server is fully loaded, you can contact the provider and ask them to terminate some processes. However, solid providers usually contact clients themselves. Running a lot of heavy processes can affect the work of other sites on the server.

If you use a VPS or a dedicated server, you manage the processes yourself. You can check them with the top command, and if needed, terminate some of them using the command:

kill -TERM [PID]

  • “PID” – the process number you got with the top command; 
  • “kill -TERM” – the safe method to terminate the failed process.

Terminating the processes is a temporary solution. With time, an error 500 may appear again due to heavy load. To resolve the problem, you’ll need to either upgrade your server or optimize your site. For example, disable unnecessary functionality, fix scripts, or redo database queries.

#8 Check PHP options max_execution_time and memory_limit

These parameters regulate the server behavior when processing PHP scripts to avoid spending all resources on processing. The max_execution_time is the time in seconds to execute a script. The memory_limit is the amount of PHP memory that the server can allocate for script execution.

The starting values of these parameters may not be enough for the server to execute important scripts, which will force it to send a status code 500 to your browser. How to fix internal server error? You can increase the values in the hosting control panel. In cPanel, you need to find the “Software” on the panel’s main page and open the “Select PHP Version.” Then go to “Settings,” find the specified parameters and increase their values. The settings are saved automatically.

Please note that when you change the PHP version, the custom values of the memory_limit and max_execution_time return to their default values. So you have to increase them again.

#9 Check PHP scripts for errors

The most common errors are typos: a missing letter, semicolon, or parenthesis. Also, a script may contain a link to a file, but there is no file at the specified path. As a result, the server cannot execute the script and returns a 500 internal server error.

Another possible reason is the incompatibility of a script with a new version of PHP. Various versions (obviously) differ from each other, so a script that works with PHP 5.6 may no longer work with PHP 7.2. For example, some variable is no longer supported in the new version. Also, after changing the PHP version, some extensions may be disabled by default or missing as obsolete.

#10 Check plugins and theme

Any plugin or theme is someone else’s code you embed into your website. If this code is poorly written or conflicts with other code after adding it, expect an internal server error 500. Sometimes it pops up immediately on all site’s pages after installation or update. But an error 500 can also occur after a specific action or only on one page.

To check if it’s a plugin triggering a response code 500, deactivate all of them at once and check if the error is gone. If so, turn on the plugins one by one until you find the one that’s causing the problem. If not, then it’s something else. Similarly, you can check your theme – apply the standard theme instead of the current one and check your site.

Wrap-up

Now you know what server error means. As you can see, a status code 500 covers a wide range of errors. Fixing it is not just about getting rid of a temporary inconvenience but also keeping your SEO solid. How to fix a server error? The most straightforward way to fix an error 500 is to check all the logs to find the cause. Alternatively, we have listed a few more options that give a good notion of how to fix server error.

None of the tips worked? Unfortunately, this can also happen. A 500 internal server error is very specific, so it’s nearly impossible to consider all situations in one article. Try to google the error 500 fragment – perhaps someone had the same problem, and its solution was described in some forum. You can also drop the error 500 fragments in the comments to this article, and we will try to help you. Good luck!

Related Posts

Want a free SEO consultation?

Schedule a call, and we'll be happy to help with your project

Written by