Memory Limit Exhausted | Increase WordPress Memory Limit

Did your WordPress website run into the PHP Fatal error “Allowed memory size of 134217728 bytes exhausted”?

Did you get an error 500 from time to time without any apparent reasons, or did the WP STAGING backup or cloning process stop?

That can happen if there is not enough memory assigned to PHP or if the memory consumption of your WordPress Installation is limited.

Increasing The WordPress Memory Limit

Try, first, increasing the WordPress Memory Limit.

Open the file wp-config.php and paste the code below just before the line that says, That's all, stop editing! Happy blogging.:

define('WP_MEMORY_LIMIT', '256M' );

Sometimes you don’t have that line That's all, stop editing! Happy blogging. in your wp-config.php

In that case, make sure you add the WP_MEMORY_CODE constant before this block of code appears:

/* That's all, stop editing! Happy blogging. */
/** Absolute path to the WordPress directory. */
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');
/** Sets up WordPress vars and included files. */
require_once(ABSPATH . 'wp-settings.php');

Take care: If you add it at the end of the wp-config.php and not before this block, the modification will not have any effect.

Now, check again if your memory errors are resolved.

If this does not resolve your WordPress / PHP memory issues, follow the advice below:

How to fix the “Memory Exhausted” Error

First of all, check out how much memory is assigned to PHP and look at the system info log. Go to WP Staging > Tools > System Info to do so:

This should be at least, say 128M or, even better 256M or more.

A more precise alternative is to create an empty file and add the code below into it:

<?php echo phpinfo();

Please save the file as info.php and upload it to your website’s root via FTP or a file manager plugin.

Now open and find the line memory_limit

This line tells you the exact amount of memory in megabytes your site uses.

For medium WordPress sites, this memory limit should be at least 128M or better 256M.

If the memory limit is lower, you need to raise it. You can increase the PHP memory limit by editing the PHP.ini. Open the PHP.ini and find the line memory_limit and change the value to:

memory_limit = 256M

Please ask your hosting provider where you can find the PHP.ini.

If you have no access to that file, you can try to edit your .htaccess file and add the code below to it:

php_value memory_limit 256M

Now, open the file info.php or the system info log again and check if the memory limit increases.

If you were successful and phpinfo() shows the correct memory limit, start WP STAGING again, and the error “Allowed memory size exhausted” should be solved and gone.

If you cannot increase the memory limit on your own, please ask your hosting provider if they can do it for you.

Updated on March 13, 2022