How to fix the WordPress "Allowed memory size exhausted" error
The error "Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes)" means a WordPress page needed more PHP memory than it is allowed to use. You may see it as a white page, a "critical error", or a failed import, backup or page-builder save. This guide explains how to raise the WordPress memory limit correctly, and how to find what is eating the memory so the error does not return.
Understand the numbers
The first number is the current limit in bytes. 134217728 bytes is 128 MB, 268435456 is 256 MB. The second number is how much more the script tried to use. If the limit is low (for example 64 MB or 128 MB) and you run WooCommerce or a page builder, raising it usually solves the problem. If the limit is already high, a plugin or a heavy task is probably the real cause.
Step 1: Raise PHP memory_limit from cPanel
WordPress cannot use more memory than PHP allows, so start here. Use the tool your cPanel shows:
- Select PHP Version → Options tab → set
memory_limit, for example to256M. - or MultiPHP INI Editor → Basic Mode → choose your domain → set
memory_limit→ Apply.
The values available may be limited by your hosting plan. If you cannot select the value you need, contact support.
Step 2: Tell WordPress to use it
WordPress has its own limit for the front end (40 MB by default on single sites, which it raises automatically if PHP allows more). To set it explicitly, open wp-config.php in File Manager and add these lines above the "stop editing" comment:
define( 'WP_MEMORY_LIMIT', '256M' );
define( 'WP_MAX_MEMORY_LIMIT', '256M' );
- WP_MEMORY_LIMIT applies to the website pages.
- WP_MAX_MEMORY_LIMIT applies to the dashboard and heavy admin tasks such as image processing and updates.
memory_limit in PHP is 128M, setting 256M in wp-config.php has no effect. Raise PHP first.Check the result in Tools → Site Health → Info: look at Server → PHP memory limit and WordPress Constants → WP_MEMORY_LIMIT. WooCommerce users can also see it in WooCommerce → Status.
Step 3: Find what is using the memory
Raising the limit hides the symptom. If the error comes back, find the cause:
- Read the error in the
error_logfile or the debug log. The file path after "in" often points to the plugin. See How to enable WP_DEBUG and read the WordPress debug log. - Think about when it happens: during a backup, an import, image regeneration, a big report or a specific page.
- Deactivate plugins you do not need. Common heavy users are backup plugins running on the site itself, statistics plugins that log every visit, broken link checkers and badly coded add-ons.
- Clean the database: old revisions, expired transients and huge logs make queries load more data than needed.
- Use a supported PHP version. Newer PHP versions generally use memory more efficiently. See How to change the PHP version.
Memory error or account resource limit?
Your hosting account also has overall resource limits that keep each website isolated and stable. They are different from the PHP memory limit:
| You see | Meaning |
|---|---|
| "Allowed memory size ... exhausted" | One PHP request reached memory_limit. Follow this guide. |
| 503 or 508 errors, "Resource Limit Is Reached" | The whole account reached its resource limits, often from heavy traffic, bots or many simultaneous processes. |
If you see the second type, check Resource Usage in cPanel if it is available and contact support. Caching helps a lot here; see How to Speed Up Your WordPress Website.
Frequently asked questions
How much memory does WordPress need?
A simple site works well with 128 MB. WooCommerce stores and sites with page builders are more comfortable with 256 MB. Higher values are rarely needed for normal pages.
Can I just set the limit to -1 or a very high number?
Avoid it. An unlimited limit lets one broken plugin use all your account's memory and slow down the whole site. Fix the cause instead.
I raised the limit and nothing changed. Why?
Make sure you changed the setting for the right domain and PHP version, that there is no old php.ini or .user.ini overriding it, and that you did not define WP_MEMORY_LIMIT twice in wp-config.php.
Need help? Open a support ticket or message us on WhatsApp +20 127 113 3655.