500 Internal Server Error in wordpress websites is one of the most irritating things for any website-owner and also to the readers of his site.
You have an old blog that works fine daily and suddenly, when you wake up in the morning; you see some weird thing in browser. The browser, instead of displaying the correct content, is showing you internal error 500.
I can understand how devastating feeling comes after seeing this as I had been myself a victim of this disease. And the more frustrating thing that this error itself is not self-explanatory. One cannot judge the reason that why it is coming.
First of all, let’s see what it is.
What is 500 Internal Server Error
To know the reason of this bug, let us see the below image. This is the screenshot that I have taken from one of my sites, on which I show this bug.
As you can see from above image, the website’s server is unable to complete the request requested from browser.
To go in more detail, wordpress saves its posts in the database. Whenever we open any post on a site then the code establishes a connection to the database and fetches the content from any of the tables in database and shows it on the page. This flow of request takes place in server-container and if for any reason, the server is unable to complete this flow then it displays the internal server 500 error.
But there can be numerous reasons for server to show this bug and with this little information; we cannot land on a conclusion. If you are a developer then you can debug the code in your local machine but how to debug and see the detailed logs on a live website?
Set debugging to true
Thanks to wordpress that allows us to debug the live sites and that too, just with a small tweak.
• For turning the debugging on, login to cpanel.
• Head over to File Manager.
• Head on to public_html folder.
• Inside the folder, search for wp-config.php file.
• Download the file and search for the text WP_DEBUG.
• Change its value to true as shown below:
• Save and upload the file back to public_html folder.
• Now, the debugging is on.
Reload the website in the browser. Now, you should be able to see the detailed logs describing the issue clearly. See if you get some reason and you can solve it easily. Make sure that you off the debugging after knowing and solving the issue as leaving the debug option as true in production environment can make your website an easy prey to any good hacker. Also, the logs would end eating up your server-space.
How to fix internal server 500 error
We are going to show here the different ways by which you can resolve the internal error 500.
1. Deactivate the plugins
Many-a-times the issue is due to the plugins installed on your blog. So, if you are able to access to the dashboard admin area, then try deactivating all the plugins. After deactivating, reload your site. If the site loads fine then it means there is problem with any of your plugins.
Now our job is to find the culprit one. Try to activate each plugin one-by-one and side by side, reload your blog once you activate any plugin. Doing this activity will help you in nailing down the erroneous plugin.
If on deactivating all the wp-plugins also does not help in the proper functioning of your blog then it means the problem is somewhere else. So, try moving to our next solution.
2. Deactivating the theme
Although the chances are very less that your working theme has got corrupted; but then also as a part of troubleshooting, we should try this option too.
WordPress by default comes with few free themes. Activate any of the themes and see if the error goes away. If you have not kept any default theme in your dashboard then try installing any free theme from official directory. Activate it and see if your blog is reloading properly. If switching the theme also didn’t help you then go to solution number 3 below.
3. Checking corrupt htaccess file
There might be chances that your htaccess file hot corrupted. Though the chances of it are less but it can also be a possible option.
• Login to cpanel.
• Go inside public_html folder.
• Download the .htaccess file on your computer.
• Make a back of this htaccess file.
• Delete the .htaccess file in public_html folder on the server.
• Try reloading your website.
• If it loads properly then grab a coffee. You have sorted out the problem.
• But you need to create proper htaccess file for your site to function properly. In order to do this, go to your blog’s dashboard. Go inside Settings –> Permalinks.
• Click on button Save Changes.
• This will create new .htaccess file.
• Also, make sure that if you had manually added some rules in this file (long back) then you need to copy them in this new file. But do it carefully else again you can land yourself in 500 internal server error.
4. Increase PHP Memory Limit
WordPress websites are coded in php language. When a user visits your website then the request goes to server and the server sends a response back to user. This request and response flow is handled by php engine. Whether your blog is showing some content to user or it is sending an email to your subscriber or sharing any article on social media; whatever activity triggers on your site are carried by php coding and internally, php engine.
Since a web hosting company sells its hosting plans to a number of customers, it allocates some php fixed memory space to its every customer. And when the memory load increases (due to spike in traffic or any newly installed plugin issue) then the web host does not allow crossing the memory limit and as such, 500 internal server error is thrown.
In order to avoid this, we are showing you that how you can tweak your wordpress.
• Go inside public_html directory.
• Download wp-config.php file on our local computer (in order to keep a safe backup).
• Paste below code below WP_DEBUG. Refer to the image below:
define('WP_MEMORY_LIMIT', '256M' );
• The above code is simply telling the server to allocate 256 MB of memory to PHP engine.
• You can increase memory limit either to 64M, 128M, 256M, 1024M or to 2048M etc. But as an ideal thing, 256M should work for you. And if it does not work then you need to contact your web hosting company to change it for you.
Although the best way to increase php memory is using wp-config only, which I have explained above but there do exist other ways too, which are being explained below.
• On your local desktop, create a file by the name php.ini. Please note the extension (its .ini).
• Paste below code in that file and save it.
memory_limit = 64M
• Again, you can increase the memory limit to any value (in the multiples of 8). See the values in above section.
• Head over to public_html/wp-admin directory and upload this file into it.
• In your public_html folder, you will find .htaccess file.
• Download it on your pc (to make a backup).
• Scroll to the bottom of file.
• Add one of the below codes. Do not add all three. Try adding only one. The code depends based on your PHP version. Test by adding all three and see, which one works for you.
This is general code with no-version check and no check of mod_php in apache.
php_value memory_limit 128M
This code checks mod_php in apache and is for php5.x
<IfModule mod_php5.c> php_value memory_limit 128M </IfModule>
This code checks mod_php in apache and is for php7.x
<IfModule mod_php7.c> php_value memory_limit 128M </IfModule>
• Upload the file back to server.
5. Re-uploading wp-includes and wp-admin folders
• If your wordpress core files have got corrupted then we should replace them.
• In order to do this, go to official wordpress website.
• Click on the button – Get WordPress.
• It will download the fresh copy of wordpress.
• Using any FTP client such as Filezilla, upload both these directories in public_html folder.
• When it asks for Overwrite, then select “Always use this action” and click on Ok.
• Try to refresh your blog and see if this solution has worked.
6. Contact your web hosting company
If none of the above solutions worked for you, then you are left with only one option and that is to contact your web host. They will be able to resolve your issue.
Let us know which solution worked for you.