What is 500 Internal Server Error – How to Fix It?
Along with client errors, server errors are the most common type of HTTP error codes encountered in website development. When a web server is unable to process a request or an error has occurred in the processing of a request, the server will return a HTTP error code, which is a 3-digit “5XX” code (usually from 500 to 599) that corresponds to the particular error that was encountered. Given its generic nature, a 500 internal server error is quite confusing for developers as it doesn’t pinpoint the exact reason behind it, and many things can cause a 500 status code to be returned by the server. The task of determining the exact cause falls on the web developer, and at times, this can be somewhat of a frustrating experience.
In this article, we’ll look into how to deal with a 500 internal server error both from a website user’s perspective and a web developer’s perspective, the possible reasons behind such a server error, and provide tips on how to fix it.
Also Read: What is MySQL Error #1064?
What to do as a User When a 500 Internal Server Error Occurs?
Your internet connection or computer are usually not at fault when this server error appears while you’re browsing a webpage. The problem is caused by the website’s server. Trying to refresh the webpage by pressing the reload button in the web browser can help. However, if you’re not just simply browsing a page, but you’re in the process of ordering a product or service, you may want to get back on your order later as refreshing the page may cause your credit card to be charged multiple times. Although respectable ecommerce sites have a mechanism in place to prevent credit card charges while a server error occurs, it’s best not to test this on yourself.
Possible Reasons Behind a 500 Internal Server Error and Fixes
As a web developer, you may encounter a 500 internal server error while managing your own server. When this happens, you need to diagnose the cause and troubleshoot the error. The best way to get to the root of the problem is to check the error log. If you have cPanel included with your web hosting plan, you can easily access the cPanel Error Log under Logs. This will reveal a list of the latest error messages that have been generated, the date and time, description or the error, and information about the file or folder generating the error. All this information will give you an insight into the cause of the server error, which can have any of the following reasons behind it:
1. Incorrect File Permissions
Wrong file permissions can be the culprit in case of a 500 internal server error. You can easily change the PHP file permissions by using your cPanel’s File Manager or by using an FTP client. Set both the parent folder and directories, and the .htaccess file to 755. After adjusting the file permissions to the correct value, refresh the page to see if there are any changes.
2. Corrupted WordPress plugin(s) or Corrupted .htaccess File
Some of the plugins you may be using on your WordPress site may also be responsible for 500 internal server errors. If you can access your Admin area, then try deactivating all your plugins and if the error disappears, proceed to reactivate your plugins one by one, refreshing your site after each re-activation to identify the one causing the issue. Once you’ve managed to pinpoint the faulty plugin, delete it from your WordPress site. If you’re unable to access your Admin area, you need to work via FTP to access the root directory and explore the WP-content folder and access your plugins. To deactivate or disable them, simply rename them. If the 500 internal server error disappears as a result, the problem was most likely caused by a corrupted plugin.
If these steps don’t lead to results, you may need to check if there is a problem with your WordPress theme by resetting the theme to the Twenty Fourteen theme. If this does not fix the problem, you need to check for corrupt .htaccess file. Locate your .htaccess file (via cPanel or FTP) and rename it (e.g. rename it to error_htaccess), then refresh your site to see if it solved the problem.
3. TimeOut Sessions
When a script is taking longer than usual to process, the server will kill the process, leading to the displaying of a 500 internal server message, when in fact it should display a 504 Gateway Timeout error message. This issue is fixed by the hosting company setting the timeout duration to a higher value.
4. Script Error
An error in the programming code of the Perl script can also cause a 500 internal server error. Sometimes, something as banal as a missing character (e.g. a missing semicolon) may be the cause. So check the code for any coding or syntax errors.
5. PHP Memory Overuse
Overloading that occurs on the PHP memory of the server can also be a reason why a 500 internal server error appears. You can fix this by increasing the maximum memory limit by creating or editing a php.ini file with the following directive: memory_limit = 64MB. Increasing your PHP memory limit is more of a quick fix than a permanent solution, and you need to identify what caused the memory overuse in the first place. It may be caused by a faulty plugin or some theme function.
6. Error in Cached Version of Page
An error with the cached version of the page on your browser is another thing you should check for. Go to your web browser’s history and clear all cache and cookies, then refresh the page to see if change made the error go away.
If none of the above solutions succeed in solving the problem or you have no experience with fixing errors of this nature, you need to get in touch with your hosting provider’s customer support team that can assist you in dealing with this error.
The vagueness of 500 internal server errors makes them one of the most frustrating type of server errors. Examining the error log in your control panel and going through the possible fixes listed in the above checklist of the most common reasons behind a 500 internal server error can greatly expedite the process of getting rid of the problem.