Recently, I encountered a 520 Internal Server Error on my other WordPress site.
I originally thought this error was caused by the WordPress plugin.
After I disabled all plugins, this error still exists.
After turn on the WordPress Debug mode, I found the following error in the debug log:
PHP Fatal error: Allowed memory size of xxx bytes exhausted (tried to allocate xxx bytes) in /path/to//wp-includes/wp-db.php on line 1978
I noticed that this is an internal server error caused by the memory size.
Why did this error occur?
By default, WordPress will attempt to increase memory allocated to PHP to 40MB for single site and 64MB for multisite.
My site exceeds this limit and gets the Memory Exhausted Error as noticed above.
How did I find this error:
1. Turn on the Debugging mode on your WordPress site.
- Open the
wp-config.phpwith a text editor.
- Set the
2. Enable the Debug Log by adding the following PHP snippets to the
define( ‘WP_DEBUG_LOG’, true);
3. Save the
wp-config.php and upload it to your server.
4. Visit your WordPress site.
5. Check out the
debug.log file under the wp-content folder. You will see the details about the 520 error:
[09-Apr-2018 10:54:12 UTC] PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 7446629 bytes) in /path/to/wp-includes/wp-db.php on line 1978
How did I fix this error:
1. Open the
wp-config.php with a text editor.
2. Set the
WP_MEMORY_LIMIT to 256MB.
3. Save and upload the
wp-config.php file. Done.
Thanks to the WP_DEBUG_LOG!