How to check and increase your WordPress site's memory limit

WordPress can sometimes run out of memory. This isn't very common, and usually only happens on either extremely busy or fully featured sites (lots of plug-ins and/or functionality) or if there's a code issue with a theme or plug-in being used.

You'll often see an error something like -

Allowed memory size of xxxxxx bytes exhausted.

or

Fatal error: Out of memory

followed by some detail about what was allocated/attempted to be allocated and what file was making the request - this can often be a clue as to where to look for any code issues.

Sometimes, however, it may just be a case that the site needs more memory available in order to run.

We always recommend that you run your site using the latest supported version of PHP, along with the latest version of WordPress and any theme and plug-ins.

From version 5.0 of WordPress, there's a useful Site Health tool built into WordPress so you can see what memory limits are set.

  1. You can find the Site Health under the Tools menu in the WordPress dashboard. Click the Info tab a the top.
  2. First of all, check the Server section. This will show the PHP memory limit set on the server.
    The WordPress PHP limit can never be higher than this. So, if this is low you'll first need to increase the server PHP limit. We have a separate guide that covers changing PHP settings - link opens in a new tab. Once you've increased the server's PHP memory limit, come back and refresh/reload the Server Health page and you should see the new limit.
    You could re-test your site at this point and all may be well - but the next step will allow you to check and confirm if WordPress is using this new limit automatically, or whether you need to make some further adjustments to tell WordPress to use a higher limit.
  3. If you've checked you server limit and that's set as required the next step is to check your WordPress limit which can be set independently - but would usually set itself to the server limit.
    Expand the WordPress constants section on the Site Health page.
    You'll see here the WordPress max memory limit.
    However, WordPress has two memory limits you can set.
    WP_MEMORY_LIMIT - this sets the PHP limit for the front-end of the site - this would usually be what you'd need to set if your site was experiencing fatal errors.
    WP_MAX_MEMORY_LIMIT - this sets the PHP limit for the admin area of the site - this can be set higher, or lower than WP_MEMORY_LIMIT as sometimes admin functions - like using third-party page builders can require more memory than is required to serve the site to visitors.
  4. To confirm, or set these limits if they are lower than your server PHP limit you'll need to edit the WordPress wp-config.php file.
    You'll find this file in the root directory of your site. You can access it via cPanel File Manager (link opens in a new window) or FTP (link opens in a new window).
    Check your wp-config.php for either of the following lines:
    define( 'WP_MEMORY_LIMIT', 'xxxM' );
    define( 'WP_MAX_MEMORY_LIMIT', 'xxxM' );
    If you find either line you can normally safely delete it to allow WordPress to use the limit you set within the cPanel PHP settings (see step 2).
    However, should you require a different limit you can add either line, with your required memory limit. Please ensure you add any additional entries above the Happy Blogging line -
    /* That's all, stop editing! Happy blogging. */
    Remember the limits you set can't exceed the server limit.
    Save your wp-config.php file and refresh the Site Health page to confirm the new limits are in place.


How did we do?


Powered by HelpDocs (opens in a new tab)
© Krystal Hosting Ltd 2002–