How can I Increase the WordPress Memory Limit

How can I Increase the WordPress Memory Limit

In this article, you’ll learn how to increase the WordPress memory limit.

When your WordPress page requires more memory than the default allocated memory, you get to see in your logs a message that looks similar to this one:

PHP message: PHP Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 262144 bytes) in /var/www/html/wp-includes/...

Table of Contents

In our previous example the, 268435456 bytes translated into MB are:

268435456 / 1024 / 1024 = 256MB

And the error message tell us it’s not enough to process our page.

But first question you have to answer is: Where is this memory needed?

Decide which WordPress memory limit to increase

WordPress lets you configure two different memory limits

  • One memory limit for your wp-admin, the WordPress backend: The WordPress admin memory.
  • One memory limit for your public-facing pages: The WordPress public memory.

You have to check when and where you get the memory error.

If you get the error while navigating on the public web, then you have to rise the WordPress Public Memory.

If you get the error while managing your WordPress from your desktop backend, then your you have to rise the WordPress Admin Memory limit.

Increasing the WordPress Public memory

To increase the memory limit for your public-facing pages:

  1. Open the wp-config.php file, which by default is located in the root WordPress directory.
    One way to access and edit the wp-config.php file is to connect to the server securely via sftp.
  2. Edit the file, and find the following text near the end of the file:
/* That's all, stop editing! Happy blogging. */

3.  Above that line, add the WP_MEMORY_LIMIT PHP global var definition with your new memory limit:

define('WP_MEMORY_LIMIT', '512M');
/* That's all, stop editing! Happy blogging. */

You can now visit your WordPress site and the memory exhausted error should disappear. If not, rise the limit a little bit more.

In some cases, rising the WordPress memory limit to a very high level doesn’t work.
Some plugin extension, or combination, may have a memory leak somewhere.

Check your last plugin installs and upgrades.

Increasing the WordPress Admin memory

For admin pages, we have to set the WP_MAX_MEMORY_LIMIT global var. The process is the same:

  1. Open the wp-config.php file, which by default is located in the root WordPress directory.
  2. Find the following text near the end of the file:
/* That's all, stop editing! Happy blogging. */

3.  Above that line, add the WP_MAX_MEMORY_LIMIT PHP global var definition with your new wp-admin memory limit:

define('WP_MAX_MEMORY_LIMIT', '512M');
/* That's all, stop editing! Happy blogging. */

One important detail to take in mind:

Some shared hosting do not let WordPress surpass the server memory limit.

the server memory defined in your php.ini file

If your new memory limit, the one defined in your wp-config.php, is not working, you will have to increase the PHP server memory limit. With wetopi your wp-config.php memory setup is enough.

Increasing the PHP server memory limit

The PHP engine limit can be set to a global default in php.ini

; Maximum amount of memory a script may consume (default 128MB)
; http://php.net/memory-limit
memory_limit = 512M

The placement of your server php.ini depends on your server provider. At wetopi you’ll find it at /var/www/conf/php.ini

NOTE: if you change this var, remember to restart your server.

REMEMBER: With wetopi your wp-config.php memory setup is enough.

We are techies passionate about WordPress. With wetopi, a Managed WordPress Hosting, we want to minimize the friction that every professional faces when working and hosting WordPress projects.

Not a wetopi user?

Free full performance servers for your development and test.
No credit card required.

See how Wetopi stacks up against your current hosting

Migrating sites to us is free and completely effortless on your part.

No hidden small text.
No commitments.
No credit card.

Try before you buy.