Troubleshooting · Guide
How to Increase the PHP Memory Limit in WordPress
Short answer
Add define( 'WP_MEMORY_LIMIT', '256M' ) and define( 'WP_MAX_MEMORY_LIMIT', '512M' ) to wp-config.php before the stop-editing line. Or set memory_limit = 256M in php.ini or .user.ini. Then check Tools > Site Health > Info > Server and repeat the task that failed.
Key takeaways
- PHP lists the default memory_limit as 128M, and -1 means no limit.
- WordPress tries to raise memory to 40 MB for a single site and 64 MB for Multisite.
- Set WP_MEMORY_LIMIT to 256M and WP_MAX_MEMORY_LIMIT to 512M for admin tasks.
- A php_value line in .htaccess causes a 500 error on hosts that run PHP-FPM.
- If a task still fails at 512 MB, a plugin or a large image is more likely at fault.
What is the PHP memory limit in WordPress?
The PHP memory limit is the most memory, in megabytes, that one PHP script may use before PHP stops it with a fatal error.
PHP lists the default memory_limit as 128M in the PHP manual.
That manual states that the setting caps the memory a script may allocate, and that setting it to -1 removes the limit.
WordPress tries to raise that limit for itself. The wp-config page states that WordPress tries to raise PHP memory to 40 MB for a single site and 64 MB for Multisite, so a WP_MEMORY_LIMIT value in wp-config.php should be higher than 40 MB or 64 MB.
When a script needs more memory than the limit allows, PHP stops it and shows “Allowed memory size of X bytes exhausted”. The number in the message is the limit in bytes, so 268435456 bytes means 256 MB.
What do you need before you start?
You need a backup, your current limit, and the name of the plugin or task that hit the limit.
Back up files and the database before you edit any server file. A wrong line in .htaccess or php.ini can stop the whole site, so a backup you can restore is the first step.
Find your current limit in Tools > Site Health > Info, then open the Server section. It lists “PHP Memory Limit” with the value your site runs, such as 128M or 256M. Write that number down before you change it.
Note which action hit the limit. An image upload, a backup, an import, or a page builder edit each point to a different cause. A limit that is too low is one cause, but a plugin that holds too much data in memory is another.
- A current backup of files and the database
- Your current PHP memory limit from Site Health
- The exact action that showed the memory error
- File access through your host panel, SFTP, or SSH
- 15 to 30 minutes, plus time to repeat the failing task
How do you increase the limit in wp-config.php?
Add define( 'WP_MEMORY_LIMIT', '256M' ); to wp-config.php before the stop-editing line, and add a higher admin limit if admin tasks need more.
This is the usual first method, because it applies to WordPress only and travels with the site when you move it. The wp-config page gives this exact line for a 256 MB limit, and notes that the setting raises PHP memory only for WordPress, not for other applications.
Follow these steps:
- Open
wp-config.phpin the root folder of your site. - Find the line that reads
/* That's all, stop editing! Happy publishing. */. - Add this line just above it:
define( 'WP_MEMORY_LIMIT', '256M' );
define( 'WP_MAX_MEMORY_LIMIT', '512M' );
- Save the file and check Site Health again.
WP_MEMORY_LIMIT sets the limit for front-end requests. WP_MAX_MEMORY_LIMIT sets a higher limit for admin screens, AJAX, cron, and image work. The wp-config page states that admin tasks may need more memory than normal operation, and that WP_MAX_MEMORY_LIMIT covers that case.
If the value in Site Health does not change, your host may cap PHP memory at the server level. In that case, no wp-config.php line can raise it above the host cap, and you need to ask support or use the php.ini method below.
How do you increase the limit in php.ini or .user.ini?
Set memory_limit = 256M in the php.ini or .user.ini file your site reads, then check Site Health.
Use php.ini when you control the server. Use .user.ini on most shared hosts that run PHP-FPM or FastCGI, because PHP reads that file per folder. Add or change this line:
memory_limit = 256M
Save the file. PHP-FPM reads .user.ini again after a short delay, often within 5 minutes. A php.ini change may need a PHP restart, which your host can do for you.
This method raises the limit for every PHP application on the server, not just WordPress. That is fine on a server that runs only WordPress, but it matters on a server that runs other PHP sites too.
Check the result in Tools > Site Health > Info > Server. The “PHP Memory Limit” row should now show 256M.
If it still shows the old value, you edited a file your site does not read. Ask your host for the path to the file it does read.
How do you increase the limit in .htaccess?
Add php_value memory_limit 256M to .htaccess, but use this method only on Apache with mod_php or a matching LiteSpeed setup.
On many modern hosts, PHP runs as PHP-FPM, and a php_value line in .htaccess causes a 500 error. Check the PHP SAPI value in Tools > Site Health > Info > Server first. If it says fpm-fcgi, use the .user.ini method instead.
Follow these steps:
- Open your host file manager and show hidden files, so
.htaccessis visible. - Download a copy of
.htaccessbefore you edit it. - Open
.htaccessand add this line at the end, outside the WordPress rewrite block:
php_value memory_limit 256M
- Save the file and load your site.
If the site shows a 500 error at once, remove the line you added and restore your backup copy. That result means your host does not support PHP settings in .htaccess. Use the php.ini method instead.
A host panel is often a safer choice than .htaccess. In cPanel, the screen is called MultiPHP INI Editor or Select PHP Version, and it sets the same value without the risk of a 500 error.
Which memory limit should you choose?
Use 256 MB for most sites, 512 MB for WooCommerce, page builders, or large imports, and ask the host when 512 MB still fails.
The table below gives a starting point for common site types. Pick the smallest value that lets your tasks finish.
| Site type | Start limit | Admin limit | Why |
|---|---|---|---|
| Simple blog, few plugins | 128M | 256M | PHP default, and a light site fits it |
| Business site, page builder | 256M | 512M | Builders hold more data in memory |
| WooCommerce store | 256M | 512M | Orders, products, and images add up |
| Large import or backup | 256M | 512M | Batches need room to process |
| Heavy image work | 256M | 512M | Image edits use memory per file |
| Still fails at 512M | Ask the host | Ask the host | A plugin fault is more likely |
PHP lists the default memory_limit as 128M in the PHP manual. A value of 256M is twice that default, and 512M is four times it.
A higher limit does not make a site faster. It only lets a script use more memory before PHP stops it.
If a task still fails at 512 MB, the limit is probably not the real cause. A plugin that loads too much data, a very large image, or a database query that returns too many rows is more likely. Raising the limit further hides that fault instead of fixing it.
How do you check the new limit worked?
Repeat the task that failed, then confirm the value in Site Health and watch for the same error.
First, open Tools > Site Health > Info > Server and read “PHP Memory Limit”. It should show the value you set, such as 256M. If it shows the old value, your change did not apply, and you need to check which file your site reads.
Second, repeat the exact task that failed. Use the same image, the same import file, or the same backup. If it now finishes, the new limit helped.
If it fails with the same “Allowed memory size exhausted” message, note the number in the message. If that number matches your new limit, the task needs more than the new limit, or a plugin is using too much memory.
Third, check the error log. A fatal error that names a plugin file points to that plugin, not to the limit. The guide on what causes the memory error covers the messages that point to a slow plugin or a large image.
If the task finishes but takes close to the full limit, split it into smaller parts. Import in batches, resize images before you upload them, or back up files and the database in two runs.
What if the limit will not change?
Ask the host to raise the server cap, or find the plugin or image that uses too much memory.
Some shared hosts cap PHP memory at the server level. The wp-config page states that some hosts do not allow the PHP memory limit to rise on their own, and that you should contact your host in that case.
It also notes that many hosts set the PHP limit at 8 MB in older setups, which is far below what a current site needs.
Ask support with a clear request: the setting name, the value you want, and the task that needs it. For example, ask for memory_limit set to 256M for a WordPress site that runs WooCommerce. A host can often raise it for one site, or raise it for a short time.
If the host will not raise it, reduce the memory the task needs. Resize images before you upload them, import in smaller batches, and turn off plugins you do not use. The guide on how much RAM WordPress needs covers the wider question of server memory for a WordPress site.
A plugin that uses too much memory will keep failing at any limit. Turn on debug logging, repeat the fault, and look for the plugin folder name in the newest entries of wp-content/debug.log.
What mistakes should you avoid?
Do not set the limit to -1, do not edit the wrong php.ini file, and do not use .htaccess on PHP-FPM.
The most common mistake is setting memory_limit to -1 in php.ini or WP_MEMORY_LIMIT to a very high value. The PHP manual states that -1 means no memory limit, so a faulty script can use all the memory on the server. Use 256M or 512M instead.
A second mistake is adding a php_value line to .htaccess on a host that runs PHP-FPM. That step causes a 500 error on every page, and the site stays down until you remove the line. Check the PHP SAPI value first.
A third mistake is editing the command-line php.ini file instead of the web php.ini file. The two files are separate, and a change to the command-line file will not affect web requests. Ask your host for the path to the web php.ini file if you are not sure.
Other mistakes to avoid:
- Editing
.htaccessorphp.iniwith no backup copy saved first - Raising the limit to hide a plugin that uses too much memory
- Changing the limit and the plugin at the same time, which hides the cause
- Forgetting to check Site Health after the change, so you never know if it applied
Check your PHP version while you are here. WordPress.org recommends PHP 8.3 or greater, with MySQL 8.4 or MariaDB 10.11 or greater, and notes that WordPress also runs on PHP 7.4 and MySQL 5.5.5 in legacy installs.
A newer PHP version uses memory more cleanly than an old one, and the guide on checking your PHP version shows where to find the version your site runs.
Frequently asked questions
What is the default PHP memory limit for WordPress?
PHP lists the default memory_limit as 128M. WordPress tries to raise it to 40 MB for a single site and 64 MB for Multisite, so a WP_MEMORY_LIMIT value should be higher than those numbers, such as 256M.
What is the difference between WP_MEMORY_LIMIT and WP_MAX_MEMORY_LIMIT?
WP_MEMORY_LIMIT sets the limit for front-end requests, while WP_MAX_MEMORY_LIMIT sets a higher limit for admin screens, AJAX, cron, and image work. Set the first to 256M and the second to 512M when admin tasks need more memory.
Does the .htaccess method work on every host?
No, not on most modern hosts. If PHP runs as PHP-FPM, a php_value line in .htaccess causes a 500 error. Check the PHP SAPI value in Site Health first, and use php.ini, .user.ini, or wp-config.php when it says fpm-fcgi.
Is it safe to set the memory limit to -1?
Setting memory_limit to -1 removes the limit, so a faulty script can use all the memory on the server. Use 256M or 512M instead, and fix the plugin or task that uses too much memory rather than removing the limit.
How do I check my current PHP memory limit?
Open Tools > Site Health > Info and expand the Server section. It lists the PHP memory limit, PHP version, and time limit. If it still shows the old value, your host may cap memory at the server level.
What can I do if my host will not raise the memory limit?
Resize images before you upload them, import in smaller batches, and turn off plugins you do not use. Turn on debug logging and look for the plugin folder name in wp-content/debug.log, because a plugin that uses too much memory will keep failing at any limit.
Sources
- Editing wp-config.php WordPress Developer Resources
- Description of core php.ini directives PHP.net
- Requirements WordPress.org
- Debugging in WordPress WordPress Developer Resources
- Troubleshooting your site: Plugin and theme conflicts Learn WordPress
Is your product missing, or something out of date?
Tell us what to add or correct. We read every note and reply when we need a source. A message does not buy a ranking.
Thanks — we review requests within 3 business days.
