I ran into this problem over the last few days. I’m using BackupBuddy for backups on many of my websites, and when it’s backing up a large zip file (over 1GB), 256MB might not be enough to complete the backup job successfully. I think it might be helpful for you to have all of this information in one place.
Here’s what you need to know to increase your wordpress memory limit.
Your wordpress memory limit cannot exceed your PHP memory limit.
You must have a php memory limit that is greater than your wordpress memory limit.
The php memory limit can be set 2 ways. I am using 512MB as my amount, but you can set this to whatever you would like.
Many shared hosting providers limit your memory usage to 32MB or 64MB. If you are on shared hosting you are likely to run against your hosting before you hit the 256MB maximimum memory wordpress limit. If you are on shared hosting, you are unlikely to be able to edit your php.ini, but may be able to make the change to the htaccess file (within the constraints of your hosting limits.)
1. You can set the memory limit in the php.ini file. The syntax for setting this in the php.ini file is:
memory_limit 512M
2. You can set the memory limit in the .htaccess file. The syntax for setting it in the .htaccess file is:
php_value memory_limit 512M
If you want to see what your php memory limit is, or where your php.ini file is located on your server you can put this code in a file, and name it something like phpinfo.php
<?php phpinfo(); ?>
This file should be located in your main website root directory. It will tell you all about your php installation including which modules are loaded, memory limits, and much more.
Once you have verified your limit is showing correctly for your phpinfo, remove that file from your website. This file being publicly available under a name like that is a security risk because it gives a hacker all sorts of information about your server, and potential vulnerabilities.
Your WordPress Memory Limit Cannot Exceed Your WordPress Maximum Memory Limit
This is the tricky part. In older versions of wordpress, the Maximum memory limit for wordpress was hard set at 256MB and wasn’t available as a global variable that could be set in the wp-config.php file.
The line to set your wordpress memory limit to 512MB:
define(‘WP_MEMORY_LIMIT’, ‘512M’);
The catch is that there is an additional variable that sets the Maximum wordpress memory value to 256MB by default. this variable is called wp_max_memory_limit. Here is the line to add to your wp-config to increase the maximum wordpress memory beyond 256M:
define(‘WP_MAX_MEMORY_LIMIT’, ‘512M’);
You really don’t want your frontend wordpress memory use to be any bigger than necessary. A very high frontend wordpress memory limit could cause you to run out of memory on your server, and potentially crash it. If you only want to increase the limit for the admin panel to 512M, but you want to leave the front end of wordpress at 128M, you would use these lines instead.
define(‘WP_MEMORY_LIMIT’, ‘128M’);
define(‘WP_MAX_MEMORY_LIMIT’, ‘512M’);
This sets the admin panel to 512M because admin_memory_limit is set to whatever value is in WP_MAX_MEMORY_LIMIT in wp-admin/admin.php. This has been the case since wordpress 3.0
That core code looks like this:
@ini_set( ‘memory_limit’, apply_filters( ‘admin_memory_limit’, WP_MAX_MEMORY_LIMIT ) );
If you have more questions about wordpress memory limits, leave me a comment below.
Excellent advice. I’ve been suffering a memory problem for weeks now. My hosts added a php.ini file to up the available memory to 512Mb, but it was only the max_memory_limit that actually fixed it for me. Thanks!
Hi this information is really useful,
I also want to raise my admin memory.
But it is not really clear for me where to add this:
define(‘WP_MEMORY_LIMIT’, ‘128M’);
define(‘WP_MAX_MEMORY_LIMIT’, ‘512M’);
Some good info here, especially being careful to limit front end memory. Always good to increase the operating memory of WordPress but with restrictions.
Thanks for the tips 🙂
hi, i have some problems to import all articles (450) of my joomla database , i’m using the Import Joomla (FG) plugin and it imports only half articles. what is the problem? i already set
define(‘WP_MEMORY_LIMIT’, ‘128M’);
define(‘WP_MAX_MEMORY_LIMIT’, ‘512M’);
in my wp-config.php
Thanks
Hello,
I met a new issue. How can you explain the following?
Upto now my wordpress and PHP memory limit were set to 256 Mb. Everything was fine.
But a few days ago, I had some plugins which didn’t work anymore with all the time the same error 500 related to admin-ajax.php
The way I was able to solve the issue was to set the php limit to 512, while keeping the wordpress limit to 256.
My guess is that you were running up on the 256MB wordpress limit, which caused you to exceed the 256MB PHP limit. PHP has other modules running, and giving wordpress all of what is allowed to PHP could cause php to overload. Good question, Olivier!