Your plugins aren’t working. Your site isn’t loading. You keep seeing the error “Allowed memory size exhausted” and it keeps saying to increase your PHP memory limit. What is that and how do you solve it?
The PHP memory limit exists to stop RAM-hogging resources from bringing down your site. But sometimes it can also cause problems, such as when you install a plugin that needs a little extra power and ends up cutting off access to your site.
When you’re encountering the white screen of death due to lack of memory, you need to get this issue fixed right away. Let’s get into what the PHP memory limit is and how to resolve it if you hit the resource ceiling.
What Is PHP Memory Limit?
The PHP memory limit sets the maximum amount of memory any script on your website can use. But what exactly does that mean?
Your website is powered by servers, which are just specialized computers used to keep the backend of a website running. Like normal computers, they use components like processors, storage, and RAM — also known as memory.
RAM is one of the most important parts of a server. Every program and application takes up a little bit of memory. The more intensive the program, the more memory it takes. When you run out of memory, your site will run sluggishly or even refuse to load.
Web applications, such as WordPress plugins, are one of many things that may take up memory on your server. Usually, these applications take up a very small amount of space, and you’ll never encounter any issues unless your host has given you very little memory to work with.
But there’s also a hard cap on how much memory any PHP application’s script can take up on your server. When one of these scripts goes over the limit, that’s when you’ll start encountering problems.
You’ll see a white screen with an error, and it may even bar access to your entire site.
Why Is There a Memory Limit?
Imagine something goes wrong on your server. Maybe a program gets stuck in an infinite loop and just keeps taking up more and more memory, or an attacker tricks you into installing something that runs a malicious script to hog all your resources.
When PHP processes get out of control, the memory limit serves to put a hard stop on that before they can crash your entire server or eat up all your allocated resources for the month.
Most legitimate PHP scripts are very small. Each individual script should only take up a tiny amount of RAM, unless you have an unusual program that needs more resources in one script than most programs will ever take as a whole. These types of plugins certainly exist, but they’re rare.
If you’re running out of memory, there’s a decent chance there’s a broken or malicious PHP program, and so the memory limit error kicks in.
But sometimes you really are using a large plugin that needs extra memory. Some web hosts also set the PHP memory limit very low, so that can cause the error to appear even when you’re not installing an exceptionally power-hogging application.
Either way, you’ll quickly encounter the memory exhausted error.
The Memory Exhausted Error
So you’ve encountered the memory exhausted error. You’re probably encountering a white screen with an error message, either across your entire site or when performing certain functions such as submitting a form.
This is a serious problem, especially when it’s affecting your entire website. Every hour that passes is a lot of lost visitors.
The culprit is likely a very large or misconfigured plugin. Because WordPress plugins are coded in PHP, they’re subject to the PHP memory limit.
You can find the plugin causing the problem by disabling your plugins one by one until access to your site is regained. Once you’ve identified it, check the documentation and see if it says how much memory it needs to run.
You may want to submit a ticket to the plugin developer if there’s no indication that it’s supposed to be an exceptionally powerful plugin, as it may be buggy. Remember, the PHP memory limit only affects single scripts, not the plugin as a whole. So there’s a good chance a script got stuck in an infinite loop or some other glitch.
The issue could also be on you. Perhaps your memory limit is set far too low so only the tiniest of plugins can run correctly. Or maybe you’re trying to install a plugin that requires you to lift the limit higher than normal.
In either case, you should try to increase the PHP memory limit. Let’s show you how to do that now.
How to Increase PHP Memory Limit in WordPress
Before doing anything, there’s an easy way to check what your current PHP memory limit is without having to dig through any files. If you’re running WordPress 5.2 or later, go over to Tools > Site Health in your backend.
Install the Health Check & Troubleshooting plugin if you don’t see it.
Under the Info tab, you’ll see your PHP memory limit. If it’s already set fairly high, one of your plugins might just be broken.
However, if you find it’s very low, you’ll need to increase it by editing your wp-config.php file.
This won’t always fix the problem. Ultimately, the PHP memory limit is set by your web host. Sometimes your site is set to use fewer resources than your host offers, and tweaking your files can fix this. But if their hard-coded limit is too low, you won’t be able to actually increase it no matter how high you manually set the number.
But it’s worth a shot, so let’s go edit that file now.
What Is Kinsta’s PHP Memory Limit?
Users of all Kinsta plans enjoy a default PHP memory limit of 256 MB. This should be more than enough for 99% of all WordPress plugins and is in fact far more than most plugins should ever take.
If you’re set up with Kinsta hosting and your site is configured correctly, you should never encounter a memory limit error. The maximum limit is usually set automatically in the files without any intervention needed from you.
It might still be worth going through and making sure it hasn’t been set inadvertently too low within WordPress’ settings. It’s possible that something might have changed the number and lowered the number of resources you have access to.
If you’re still having issues, you can always contact Kinsta support and ask for help fixing the issue. We can help identify a misconfigured file you may have missed.
How to Change PHP Memory Limit via FTP
To edit the wp-config.php file, you’ll need to access your site with FTP or SFTP. This allows you to edit sensitive internal files that affect how your site functions.
You’ll only be changing one line, so it should be easy. Start by installing FileZilla or another FTP client of your choice. It’s free, so no worries there. Before you start, you should also backup your website. It’s easy to accidentally break something while editing core files.
Open up FileZilla and put in your credentials. After a few moments, you should connect to your site.
Click the public folder and find wp-config.php. If you can’t find public or public-html, it may be called root, www, or the name of your website.
Open up wp-config. Be careful not to edit anything except the PHP memory limit line, as this is a sensitive file and could break your website. Look through it until you find this line: define( ‘WP_MEMORY_LIMIT’, ‘256M’ );
Change the number listed there, save the file, and close FileZilla. All done!
How to Change PHP Memory Limit in cPanel
Some hosts won’t let you edit files over FTP. Instead, they may give you access to cPanel. If this is the case for you, no worries — you can change your PHP memory limit that way too.
First step: Log in to cPanel using the credentials provided by your host. On the home screen, you’ll see a Software section with a Select PHP Version button.
Click it and, at the top of the screen, you’ll see Switch to PHP options. Scroll down until you see memory_limit with a dropdown menu. Click it and change it to the setting you want. Click Apply and you’re all done.
Not everyone will have a Select PHP Version option. Instead, you might see MultiPHP Ini Editor. If that’s the case, your steps will be a little different.
You’ll need to click that and, in the next window, Under Configure PHP INI basic settings, you should open the dropdown and select your domain. Find the memory_limit section and input the number you want. Click Apply to save your changes.
You could also try using cPanel’s File Manager. This is very similar to accessing your site over FTP. Under the Files section on your home page, click File Manager. Find your public/public-html folder (or whatever it may be called) and open up wp-config.php.
Find the WP_MEMORY_LIMIT line as outlined in the above section and change the number to what you want. Save your changes and make sure to apply them, and that’s all you need to do.
What Should PHP Memory Limit Be?
When you go to change your memory limit, your first impulse might be to set it to 900 MB or something like that — as high as you can. But this can actually be a very bad idea.
Should a script on your site break, it could quickly spiral out of control and crash your entire server. Even if your site is hosted on powerful hardware, one script eating up all the memory could still cause serious issues.
Misconfigured scripts that are unusually taxing, but not broken enough to cause problems, could also go unnoticed. Most PHP scripts are very small, and the memory limit error serves as a warning sign that something is going wrong in the backend. Set it too high and you could have messed up scripts bogging down your site without ever knowing it.
You should set your PHP memory limit as low as you can while still allowing your site to function normally.
128 MB is a good baseline. That’s a decent amount of memory that will take care of most intensive plugins. If you know you’re going to need some extra power, 256 MB will cover even the heaviest plugins. And if you know for sure you have a real powerhouse, 512 MB is the absolute maximum you should set it to. In 90% of cases, you should never need to raise the memory limit past 256 MB.
What If Changing the Memory Limit Doesn’t Work?
If after editing your PHP file you’re still encountering the memory error, one of two problems is the issue: your host has allocated very few resources, or there’s a PHP script on your server taking up way too much memory.
Again, you should go through and disable your plugins until you identify the culprit. With 128-256 MB of memory, no plugin should be taking up so much space without mentioning it somewhere in the documentation. Disable it and notify the plugin authors about what happened.
Still encountering the error even after all plugins have been disabled? There must be some conflict or other PHP application causing the problem. This is more than you’ll be able to handle on your own, so ask your web host for help.
If the issue isn’t a plugin at all, the blame likely lies on your host setting the memory limit too low. You’re probably using shared hosting, which is notorious for allocating a very small amount of memory — understandably so, since if a site is using too much RAM, it bogs down the entire system for dozens of other websites.
Your only choice here is to upgrade to a plan that provides more resources. That might end up being costly, especially if you’re just trying to install an intensive plugin on a new site. If you don’t have many visitors yet, all the other resources gained from upgrading won’t help you that much.
You could also switch to a host, such as Kinsta, which provides more memory in the first place.
Summary
The PHP memory limit exists for a very legitimate reason: you don’t want rogue processes taking up more RAM than they’re supposed to. But when you hit the limit and encounter a white screen of death while using a legitimate plugin, it can be quite annoying.
In the end, it’s up to your host how much PHP memory you have access to. If they set the bar too low, it’s impossible to increase it.
However, sometimes your site will be using fewer resources than you really have access to. In that case, it’s possible to increase your memory. Try setting it to 128 or 256 MB (as the default option for all Kinsta plans) as you don’t want it too high.
If neither of those methods is working, it’s probably a lack of allocated resources causing the problem, rather than a setting that needs changing. Contact your host and ask how to get more, or switch to a new host like Kinsta that gives you more memory than you’ll ever need.
Save time, costs and maximize site performance with:
- Instant help from WordPress hosting experts, 24/7.
- Cloudflare Enterprise integration.
- Global audience reach with 34 data centers worldwide.
- Optimization with our built-in Application Performance Monitoring.
All of that and much more, in one plan with no long-term contracts, assisted migrations, and a 30-day-money-back-guarantee. Check out our plans or talk to sales to find the plan that’s right for you.