The 500 Internal Server Error is perhaps the most annoying error you can encounter. In many instances, you can easily resolve the issue by applying the process outlined in this KB.
In a 500 Internal Server Error situation, the server has encountered an unexpected condition that prevents it from fulfilling the clients’ request. Note that essentially, there is nothing wrong with the server itself. It has simply encountered something it can’t figure out.
Note: Before making changes to the site’s code and database, it is always a good practice to take a full backup of the server, so that you can restore the site in case something goes wrong.
Resolving 500 Internal Server Error requires you to follow this process:
Step 1: Debugging the Issue
The first step is to make sense of the situation and try to make sense of the error. For this, you need to check PHP logs (part of Apache error logs) for more information about the error.
If you are unable to find the error logs there, try enabling PHP error reporting by adding the following lines to the index.php file:
|123||ini_set(‘display_errors’, 1);ini_set(‘display_startup_errors’, 1);error_reporting(E_ALL);|
If you have a WordPress website, download the wp-config.php file (located in the website’s root directory) via SFTP and open it in your preferred text editor. Search for the string ‘WP_DEBUG’. If you find the line, simply change FALSE to TRUE and upload the file again.
If the line isn’t in the config file, add the following line to the wp-config.php file:
|1||define( “WP_DEBUG”, true );|
Reload the website and see if the error changes.
If it does, and you now see a ‘fatal error’ message that points to a specific line of code in a specific file, you’re looking at a relatively simple code error. Assuming that the said error originates from a plugin or theme, you’ll need to disable the offending product and/or work on fixing the issue yourself (or have someone else take a look at it if you’re not able to work out what’s happening on your own).
Note: Once you have found the problem, remember to change the above mentioned ‘TRUE’ value back to ‘FALSE’ within the wp-config.php file.
Step 2: Check if the Admin Works
Log into the admin panel for your website. If this page loads properly and allows you to log in, you can be reasonably sure that the issue is with a plugin/extension/module or with the active theme. If the admin page loads, move on to Step 4.
Step 3: Revert Recent Changes
If your dev team pushed changes just before the 500 error was reported, you should try to revert back to the last available version. This way, you could eliminate a very probable source of the error.
It is always a good practice to test the changes on a staging website/environment to make sure everything works as intended. To help our users, the Cloudways Staging feature provides dedicated and unlimited staging sites where they can test websites changes before pushing code to live servers.
Step 4: Audit Your Plugins/Extensions/Modules
Plugins/extensions/modules can also cause 500 Internal Server Error. In general, the error occurs because of the compatibility issues caused by outdated plugins/extensions/modules or poorly coded new ones. In this context, you might encounter the error after installing a plugin/extension/module.
To find out which of your plugins/extensions/modules is causing the error, deactivate ALL of them and then reactivate them one at a time. For WordPress, Magento and similar apps, use the application Dashboard, CLI or SFTP.
If you discover the offending plugin/extension, deactivate (or better yet uninstall) it and get in touch with the developer for help.
Step 5: Check File Permissions
If none of the above works, the issue can lie with file permissions. Fortunately, the fix is simple: Simply hit the Reset Permissions button.
Step 6: Increase PHP Memory Limit
PHP libraries require a memory limit for the successful execution of PHP scripts. Increasing the available PHP memory limit from the Server and Packages tab can also fix the 500 Internal Server error. If you have defined memory limit in the application configuration files, simply increase the value in these files. Changing the PHP memory limit will also help you avoid “Allowed memory size” error.
Step 7: Debug .htaccess Issues
In many cases, rules in .htaccess file can also cause 500 Internal Server Error. This is generally caused by rules that point to modules that are not installed/available at the Apache server.
Another scenario involves recursive rewrite rules that can end up in a 500 Internal Server error.
If the Error Persists, Contact Support
If you still can’t resolve the problem, contact timewebhosting support. In the live chat session or ticket, mention this KB and let them know you’ve tried these steps. This way the support engineers would have a good starting point and can try out other fixes to make sure your server gets up and running in no time