Raising the PHP memory limit: when and how?
The message Allowed memory size of … bytes exhausted means that a single PHP process asked for more memory than the limit allows. You raise that limit in the control panel of your hosting, per site; for WordPress a line in wp-config.php can be added on top. Do check first which file is named in the error message. If the error appears out of the blue, there is usually a plugin or an import behind it, and raising the limit only hides the problem.
What the error message says
In full: Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes), followed by a file name and a line number.
- The first number is the current limit in bytes. 134217728 bytes is 128 MB.
- The second number is what PHP wanted to take on top at that moment. It says nothing about total usage.
- The file and the line show where the memory ran out.
On a live site the visitor usually sees only a blank page, a 500 error code or, with WordPress, the notice about a critical error. The real message is then in the error log. You can read more about those status codes in what the error codes 403, 404 and 500 mean.
When it comes up
With heavy page builders, large imports, web shops with many products and the processing of large photos. Rarely with an ordinary business site.
Where to set the limit
- In the control panel. At WWW4 you set the PHP memory limit per site in the control panel, which you open from the customer portal. How high you can go differs per plan. This is the most reliable route.
- In wp-config.php, for WordPress. Above the line that tells you to stop editing, add this line: define('WP_MEMORY_LIMIT', '256M'); On its own WordPress asks for only 40 MB for the front end of the site, 64 MB on a multisite, and 256 MB in the admin area. If the server limit is already higher, this line changes nothing. If the hosting does not allow a higher value, it changes nothing either.
- In a .user.ini file. On hosting that allows it, place a file named .user.ini in the root folder of the site with the line memory_limit = 256M. By default PHP re-reads that file only every five minutes. The server's central php.ini is not something you can edit yourself on shared hosting.
A line with php_value in the .htaccess file only works when PHP runs as an Apache module. Otherwise the whole site immediately returns a 500 error.
Checking that the new value applies
In WordPress, go to Site Health in the admin area, open the Info tab and look under Server: that is where you find the PHP memory limit that is actually in force.
Why raising it is not always the answer
A site that suddenly needs far more memory usually has a problem rather than a shortage: a plugin that loads everything at once, an import that does not work in batches, a function that keeps calling itself endlessly. In that last case any limit will run out, however high you set it. Raising it hides the problem.
The limit also applies per PHP process, and every visitor requesting a page at the same time starts a process of their own.
How to find the cause
- Read the path in the error message. If it contains wp-content/plugins followed by a folder name, that is the plugin where the memory ran out. Usually that is also the culprit, but not always: sometimes another plugin filled the memory.
- Look at the error log in the control panel. In WordPress, additionally set WP_DEBUG and WP_DEBUG_LOG to true and WP_DEBUG_DISPLAY to false in wp-config.php. The errors then end up in debug.log in the wp-content folder. Switch this off again when you have finished looking.
- Work out what changed. An update, a new plugin, a large import, a new theme. From now on test updates first; how to do that is explained in doing WordPress updates safely.
- Deactivate plugins one by one until the error disappears. If you can no longer get into the admin area, rename the folder of the suspect plugin over FTP or the file manager.
- Measure the usage. The Query Monitor plugin shows how much memory was used per page.
- Make the job smaller. Import in smaller batches.
The ceiling of your plan
The maximum memory limit is part of your hosting plan. The smallest plan is meant for a business site or a blog; a web shop or a site with a heavy page builder needs a larger plan. The plans are listed on hosting pricing. If you keep hitting the maximum there as well, a server of your own is the next step: read what a VPS is and when to move to one.
Frequently asked questions
I raised the limit but the error is still there. What now?
Look at the first number in the error message. If it has not changed, your setting is not being applied: the file is in the wrong folder or your plan does not allow a higher value. If the number did go up and the memory still runs out, you are looking for a leak, not a shortage.
How much PHP memory does WordPress need?
WordPress itself needs little. The plugins and the theme determine the usage, so measure your own site instead of relying on a rule of thumb.
Is the memory limit the same as the upload size?
No. Uploads depend on upload_max_filesize and post_max_size. A failed upload is not fixed with more memory.
Still stuck?
Send us the domain name, the full error message and the time it occurred via contact. We will check the server log with you.
Does it behave differently than described above, or are you stuck anyway? Get in touch with your domain name or customer number at hand and we will take a look with you.
Contact support