Skip to content
Technology for businesses since 2008

Help center · Performance

How to increase the PHP memory limit in WordPress (memory_limit)

To fix the “Allowed memory size exhausted” error in WordPress, increase the PHP memory_limit in cPanel, under Select PHP Version > Options (or in MultiPHP INI Editor, depending on which menu is available in your account). If the problem is slowness or timeouts, also adjust max_execution_time. Then check the applied value under Tools > Site Health > Info in the WordPress dashboard.

Raising the limit fixes the symptom, but not always the cause. If the error comes back even with a high value, a heavy plugin or theme is probably consuming the memory, and it is worth investigating before you raise the number again.

What the “Allowed memory size exhausted” error means

Each PHP process can use a maximum amount of memory, set by the memory_limit directive. When a script asks for more than that ceiling, PHP stops the execution and WordPress shows a message similar to this:

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes)

The numbers vary from site to site. What matters is the meaning: PHP hit the limit and stopped. It is common during large imports, generation of image thumbnails, page builders, stores with many products, and backup or migration plugins.

The three directives that matter most

Directive What it controls When to change it
memory_limit Maximum memory for each PHP execution “Allowed memory size exhausted” error
max_execution_time Maximum time, in seconds, for each execution Long imports, timeouts, 504 errors
post_max_size Maximum size of the data sent by a form (POST) Sending large files, importers

post_max_size usually goes together with upload_max_filesize. If your case is file uploads, see the upload_max_filesize error in WordPress.

How to increase memory_limit in cPanel

  1. Log in to cPanel.
  2. In the Software section, open Select PHP Version. If the icon doesn’t appear, search for “PHP” in the cPanel search.
  3. Open the Options tab.
  4. Find memory_limit and choose a higher value from the list, for example 256M.
  5. If needed, also adjust max_execution_time and post_max_size on the same screen.
  6. The changes are saved when you select the value. If there is a save or apply button, click it.
  7. Reload the site and repeat the action that caused the error.

If your account uses the MultiPHP INI Editor instead of Select PHP Version, the path is similar: open the tool, choose the domain, use basic mode, and change the same fields. The menu varies depending on the cPanel setup, so follow what appears for you.

As for the PHP version, it is chosen in the same place. See how to change the PHP version in cPanel.

How to check the current value

After making the change, confirm that the value was really applied:

  1. In the WordPress dashboard, open Tools > Site Health.
  2. Click the Info tab.
  3. Expand the Server section and look at the fields for the memory limit, the maximum execution time, and the maximum POST size.

If the value shown is not the one you set, the change may have been made on another domain or PHP version, or there is a setting inside WordPress itself that takes precedence. See the next section.

Alternative: WP_MEMORY_LIMIT in wp-config.php

WordPress has its own limit, which it tries to apply within what PHP allows. To set it, edit the wp-config.php file in the site folder, using cPanel’s File Manager, and add this line before the phrase “That’s all, stop editing!”:

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

Keep in mind that WordPress cannot go beyond what PHP’s memory_limit allows. If PHP allows 128M, setting 256M in wp-config.php won’t help. So adjust PHP first, and use wp-config.php as a complement. Make a copy of the file before editing it: a typo can take the site down.

When a high limit hides a heavy plugin

Raising the limit is a quick fix, but it can mask a problem:

  • The error comes back. If you doubled the value and the error reappears, something is consuming memory without stopping.
  • The site is slow even without errors. Plugins that run a lot of code on every visit weigh on performance, regardless of the limit.
  • The error only appears on one page or action. That points to a specific plugin or feature, not a general lack of memory.

To find the culprit, deactivate the plugins one at a time and test after each deactivation. See also 5 reasons a WordPress site is slow and what a caching plugin is for. Before you change plugins, create a backup with JetBackup.

Which value to use

Values such as 128M, 256M, and 512M are the most common, and many sites run well with 256M. Start with a moderate value and raise it only if you need to. The maximum values your plan allows vary and are not listed here: if the tool doesn’t let you choose the number you need, ask support through the contact page.

Frequently asked questions

What is the ideal memory_limit for WordPress?

There is no single number. Simple sites usually run well with 128M or 256M; stores and sites with page builders may need more. Start low, watch the site, and increase the limit if the error appears.

I increased memory_limit, but the error persists. What now?

Check Site Health > Info to see whether the value was applied. If it was, the problem is probably a plugin or theme consuming too much memory. Deactivate the plugins one by one to identify it.

Can I set a very high limit so I never get the error again?

It is not recommended. A very high limit hides poorly written plugins, and on shared hosting your plan may have a ceiling. Ask support what limit is available to you.

What is the difference between memory_limit and WP_MEMORY_LIMIT?

memory_limit belongs to PHP and applies to the server. WP_MEMORY_LIMIT is a WordPress setting, and it cannot exceed PHP’s memory limit.

Does increasing max_execution_time make the site faster?

No. It only gives a task more time to finish before it is interrupted. It is meant for imports and long processes, not for speeding up pages.

Where can I get help if the limit doesn’t change?

Contact support through the contact page, and include the domain, the value you tried to set, and what appears in Site Health > Info.

More on Performance

See all →

5 reasons your WordPress site is slow

Slow sites lose visitors and rankings. Here are five common causes of a slow WordPress site, from weak hosting to heavy themes, large images and scripts.

3 minPerformance

5 tips to optimize LCP and FCP in WordPress

Here are 5 tips to optimize LCP and FCP in WordPress. Improving Largest Contentful Paint and First Contentful Paint is key to a faster, better user experience.

3 minPerformance

Help center

Looking for something else?

See all tutorials, organized by topic.