If you have received the WordPress error “Fatal error: Allowed memory size of xxxxxx bytes exhausted”, this tutorial will show you how to increase the WordPress memory limit.
What Is the PHP WordPress Memory Limit?
WordPress sets a memory limit of 40MB by default for a single site, and 64MB for multisite (see Increasing memory allocated to PHP). This means a PHP script is capped at the default memory limit set in the file /wp-includes/default-constants.php. You may want to increase the memory limit for some plugins that require 40MB or more. For example, WooCommerce requires more memory to run and would need this setting to be increased.
What Is the Difference Between WP_MEMORY_LIMIT and WP_MAX_MEMORY_LIMIT?
WP_MEMORY_LIMIT is the memory limit set for the front end of your website. This number is low by default because it controls the memory allocation per script. Increasing the WP_MEMORY_LIMIT will not necessarily improve the performance of your website. In other words, as concurrent users access the website, memory will be allocated for each. So you should try to keep the WP_MEMORY_LIMIT as low as possible.
WP_MAX_MEMORY_LIMIT is the memory limit set for the back end of your website. Because the concurrent number of admin users will generally be small you’ll want to set this number higher to run administrative scripts and reports.
How to Check the WordPress Memory Limit
If you are unsure how to check your current WordPress memory limit settings, you can do this while logged into your WordPress website as an administrator. WordPress Constants can be found in the Tools section of the administrator menu:
Tools > Site Health > Info
Expand the WordPress Constants section to see your currently defined WP_MEMORY_LIMIT and WP_MAX_MEMORY_LIMIT. It should look similar to the below image.
How to Increase the PHP Memory Limit in WordPress
You can increase the WP_MEMORY_LIMIT and WP_MAX_MEMORY_LIMIT in WordPress by editing the wp-config.php file and adding the following:
/** Increase WP Memory */
define( 'WP_MEMORY_LIMIT', '128M' );
define( 'WP_MAX_MEMORY_LIMIT', '512M' );
When you are done it should look something like this in the wp-config.php file:
Make sure to check that the WordPress memory limit has been increased.
It is important to be mindful of the amount of memory that you allow for frontend concurrent users. Increasing the memory limit doesn’t necessarily improve the overall performance of your website. WP_MEMORY_LIMIT controls how much memory is allocated for a single script on the front end of the website. Keeping it low will prevent performance degradation for scripts that are poorly programmed. In short, you don’t want to use up all of your memory when you have a large number of users accessing your website concurrently.
For further suggestions, take a look at the articles How to Improve WordPress Website Speed and Performance, 5 Tips to Speed up WordPress Performance (Updated 2022), and How to Clean and Optimize Your WordPress Database (Updated 2022).