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:
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:
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:
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.
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.