PHP Errors

How to Fix the PHP Allowed Memory Size Exhausted Error

By ErrorNest Published Updated 4 min read
The PHP allowed memory size error means a script needed more memory than PHP allows. Raise the limit safely, then find what is using too much.
Close view of code on a computer screen
On this page

The PHP error “Allowed memory size exhausted” appears when a script needs more memory than PHP is allowed to use. The full message looks like this:

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in /path/to/file.php on line 123

The first number is the limit in bytes. 134217728 bytes is 128 MB. The file name and line number tell you where PHP ran out, which often identifies the plugin or script responsible.

Quick fix: Raise the memory limit to 256 MB in your hosting control panel’s PHP settings, or add one line to wp-config.php if you use WordPress (step 2). Then find out why the script needed so much memory, because a higher limit only hides the cause.

What causes the memory error

  • A low memory_limit setting on shared hosting.
  • A heavy plugin, import, backup or page-builder task.
  • A very large image or file being processed.
  • A coding mistake, such as a loop that never ends or loads too much data.
Rows of server racks with blue status lights in a data center

1. Read the full error message

Note the limit in bytes, the file path and the line number. A path under wp-content/plugins/ or wp-content/themes/ names the component. The same message in the server error log or in wp-content/debug.log gives you the exact moment it happened.

2. Raise the limit in WordPress

Open wp-config.php and add this line above the comment that tells you to stop editing:

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

Reload the page that failed. WordPress cannot raise memory above what your host allows, so if nothing changes, continue with the next steps.

3. Raise the limit in your hosting panel or php.ini

Many hosting panels have a PHP settings page with a memory_limit option. If you can edit php.ini or .user.ini, set:

memory_limit = 256M

Changes in a control panel normally apply at once. A php.ini edit may take a few minutes to be picked up.

4. Try .htaccess on Apache

On some Apache servers that run PHP as a module, you can add this to .htaccess:

php_value memory_limit 256M

Warning: On servers that run PHP through PHP-FPM or CGI, this line causes a 500 error. If your site breaks after adding it, remove the line straight away.

5. Check what your host allows

Shared hosting plans often cap memory per process. If you set 256M and the error still shows the old figure, the host is overriding your setting. Ask your host what the maximum is and whether a higher plan raises it.

6. Find what is using the memory

If the error returns after you raise the limit, something is using too much. Deactivate plugins one at a time and repeat the action that failed, or check the file path from step 1. Large imports, backups and image processing are common causes, so run them in smaller batches. If a critical error blocks your whole site, see how to fix the WordPress critical error.

7. Reduce what the script has to load

  • Resize very large images before uploading.
  • Remove plugins you do not use.
  • Turn on a caching plugin or server cache so pages do not rebuild on every visit.
  • Split large imports or exports into several smaller files.

What the numbers in the error mean

The error names PHP’s limit in bytes, and the number you see depends on your server’s setting. You may also see it quoted as “allowed memory size of… exhausted”. Convert the number to megabytes to see which limit you hit:

Number in the error Memory limit What to do
33554432 32 MB Raise to 256 MB with the steps above.
67108864 64 MB Raise to 256 MB with the steps above.
134217728 128 MB Raise to 256 MB. See the 134217728 bytes guide.
268435456 256 MB Find the plugin or task using the memory. See the 268435456 bytes guide.
536870912 512 MB Almost certainly a bug or runaway task. Find the cause before raising it.
1073741824 1 GB Almost certainly a bug or runaway task. Find the cause before raising it.

To convert any value yourself, divide the number by 1,048,576 to get megabytes.

Doubling works too: 134217728 * 2 = 268435456, so doubling a 128 MB limit gives 256 MB.

Frequently asked questions

What is a safe memory limit?

256 MB is enough for most WordPress sites. Very large imports, WooCommerce stores or page builders can need 512 MB. Going higher without finding the cause usually just delays the next failure.

Why does the number in the error not match what I set?

The host may be overriding it, or a different PHP configuration file is taking priority. Check the PHP settings page in your control panel.

Is this error dangerous?

No. It stops one request from completing, but it does not damage your files. It is a sign that something needs more resources or has a bug.

When to contact support

Contact your host if you cannot raise the limit or the host overrides it. Contact the plugin developer if one plugin always triggers the error, and give them the file path and line from the message.

Official resources