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/...
In our example the, 268435456 bytes translated into MB:
268435456 / 1024 / 1024 = 256MB
are not enough to process our page. But first question you have to answer is: Where is this memory needed?
WordPress Administrative and Public memory
WordPress lets you configure two different memory limits. One memory limit for your wp-admin, the WordPress backend, and one memory limit for your public-facing pages.
You have to check when and where you get the memory error.
Increasing the WordPress Public memory
To increase the memory limit for your public-facing pages:
- Open the
wp-config.php
file, which by default is located in the root WordPress directory. - 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.
Increasing the WordPress Admin memory
For admin pages, we have to set the WP_MAX_MEMORY_LIMIT global var. The process is the same:
- Open the
wp-config.php
file, which by default is located in the root WordPress directory. - 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 limits defined in your wp-config.php
are 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.