How to resolve out of memory error in PHP?

There are advantages and drawbacks to using an open source platform like WordPress. It’s flexible and infinitely scalable, but it also requires you to be comfortable with a certain amount of technical work. This is especially relevant when it comes to performing troubleshooting and resolving some of the errors that commonly arise when you’re using the platform.

On occasion, you’ll run into an error advising that you’ve hit your site’s ‘PHP memory limit’. This could be confusing at first, especially since you won’t know what caused the problem or how to fix it. Fortunately, this issue is one of the simplest ones to resolve and should be achievable even for relatively new WordPress users.

In this knowledge base article, we’ll explain what a WordPress memory limit error is, discuss why it might occur on your WordPress site, and then we’ll walk you through some of the options for fixing it.

Let’s get to work!

An Introduction to WordPress Memory Limit Errors

WordPress is a pretty stable platform, but it isn’t immune to errors. There are a number of common issues you might run across, such as the infamous ‘White Screen of Death’ or a site stuck in ‘maintenance mode’.

The good news is that most WordPress errors aren’t too difficult to troubleshoot and fix. All the same, they can be intimidating to newcomers, especially since they offer little information about what’s gone wrong and how to approach solving the problem.

This brings us to one of the most frequently-encountered problems – the WordPress memory limit error. This can also be known as a ‘PHP memory limit error’ and often looks something like this:

Need to give a shoutout here. Kinsta is amazing, I use it for my personal website. The support is rapid and outstanding, and their servers are the fastest for WordPress.

How to resolve out of memory error in PHP?
Phillip Stemann
View plans

fatal error: allowed memory size of 67108864 bytes exhausted

The error can occur in a number of different circumstances. However, it’s most likely to arise when you take specific types of actions on your site, such as:

  • Installing and activating a new theme or plugin.
  • Uploading images and other media to your site.

If you’ve run into this error on your own WordPress site, don’t worry. The reasons behind it are simple – let’s talk a little more about why it occurs.

You've reloaded a page and, boom, the PHP memory limit error slaps you on the face. Here are all the things you need to investigate to fix it🕵️Click to Tweet

Why You’re Seeing a WordPress Memory Limit Error on Your Site

The clue to the cause of the ‘memory limit’ error is right there in the name. Just like anything else, your website requires a certain amount of memory in order to store all of its data. This includes its database and files, all of your content, code added by plugins and themes, and more.

This memory is provided by your hosting server. When you purchase a hosting plan, your site is allocated a specific amount of resources, including the memory used to store your site and enable it to function smoothly for visitors.

Naturally, purchasing a higher-tier hosting plan provides more space and memory for your website. Many first-time site owners start out with basic shared hosting plans, which isn’t necessarily a problem. However, it does mean your allocated memory will be on the low side.

As your site grows larger or you start using more complex plugins and scripts, you may eventually hit your memory limit.

When it comes to WordPress, this means you’ll end up seeing a PHP memory limit error, and won’t be able to complete the action you were trying to take.

How to Check Your Current PHP Memory Limit

If you’re running WordPress 5.2 or above, you can use the Site Health tool to check what the current PHP memory limit is on your site. In your WordPress dashboard, go to “Tools” → “Site Health” → “Info” and scroll down to the server section. Here you can see that the PHP memory limit is on your server.

How to resolve out of memory error in PHP?
Check PHP memory limit

If the amount is low, say 32M, there’s ultimately only one fix for this issue: you need to increase the amount of memory allocated to your site. However, there are a few different ways to approach this.

How to Resolve the WordPress Memory Limit Error (2 Methods)

Unlike many common errors, the WordPress memory limit issue is simple to troubleshoot. It has a very clear cause, so you won’t have to go through a whole lot of trial and error if you want to figure out how it can be fixed.

Instead, there are really only two ways forward when you’ve hit a PHP memory limit on your website. You can increase the amount of memory allocated to your site or you can opt for a hosting plan that offers more space. Let’s explore when and how you’d want to use either of these methods.

Option 1: Increase the PHP Memory Allocated to Your Website

It may seem simple, but sometimes the obvious solution is the best one. If your site has run out of memory, the easiest thing to do is increase how much memory it has access to.

Obviously, how far you’re able to increase the limit will depend on your hosting provider and plan. We’ll talk more about this aspect in the next section. However, it’s not uncommon for your site to be using a smaller amount of memory than it actually has available.

Your site’s current memory limit is set in its wp-config.php file, and this may or may not match up to the limit allowed by your provider. The first step, therefore, is to try and increase your PHP memory allowance by editing the file.

Deploy your application to Kinsta - Start with a $20 Credit now.

Run your Node.js, Python, Go, PHP, Ruby, Java, and Scala apps, (or almost anything else if you use your own custom Dockerfiles), in three, easy steps!

Deploy now and get $20 off

Using an FTP Client to Access Your Site’s Files

Increasing your site’s memory limit will require logging into your site directly, using Secure File Transfer Protocol (SFTP). If you’ve never done this before, you’ll first need to install an SFTP client – a program that enables you to connect to your site’s files on its server.

We recommend picking up FileZilla, which is free and relatively easy to get started with:

How to resolve out of memory error in PHP?
FileZilla

Next, you can follow this guide to setting up FileZilla and using it to make a connection. You’ll need your site’s SFTP credentials, which you can usually find in your hosting account. If you run into trouble, you should be able to reach out to your provider, who can tell you where to locate your credentials.

Finding Your wp-config.php File

Once you have FileZilla set up and connected, you should be looking at a screen similar to the following:

How to resolve out of memory error in PHP?
FileZilla successfully connected

In the top-right quadrant, you’ll see a list of the folders that contain your site’s files. Look for your site’s ‘root’ folder, which is often either named after your site’s domain or is called public_html or www. Open this folder up, and look for a file called wp-config.php:

How to resolve out of memory error in PHP?
wp-config.php file in WordPress

This file stores certain information about your site’s database and settings. Therefore, it’s important to be careful not to alter anything other than the specific line of code we’ll be looking at. In fact, it’s a good idea to make a backup of your site before proceeding any further, just in case you accidentally delete or change something important.

Increasing Your Site’s Memory Limit

With your backup in place, go ahead and open up your wp-config.php file. It should look something like this:

Tired of dealing with WordPress memory limit errors? You won’t have this problem at Kinsta. Check out our hosting plans

How to resolve out of memory error in PHP?
Example of wp-config.php file

Then, look through the file for the following line:

define( 'WP_MEMORY_LIMIT', '256M' );

Note that the number may be different in your file, as it represents your site’s current memory limit. You may also not find this line at all.

If you do locate the line, go ahead and increase the number it contains. In most cases, 256 MB should be sufficient. If you don’t find the line, you can paste it in right before the part of the file reading: “That’s all, stop editing! Happy blogging.”

Then, save the changes to your wp-config.php file, and close FileZilla. Open up your site, and try repeating the action you tried when you first encountered the WordPress memory limit error. If it no longer appears, you’ve fixed the problem.

If you still encounter the error, you can try opening up your wp-config.php file and increasing the memory limit further. However, if you try this a few times and it doesn’t work, then you may have reached the maximum limit allowed by your hosting provider. In this case, you’ll need to try a different approach.

However, before we move on, it’s worth noting that some hosts may not let you access your site through an . In this scenario, you can often change your memory limit manually through other means, such as by using cPanel. For more details on your alternative options, check out .

Option 2: Upgrade Your Website’s Hosting Plan

Each type of hosting will provide a specific amount of resources. Sometimes, though, those resources might become insufficient for your website in time.

If you’ve tried increasing your site’s memory limit as described above with no luck, the first step would be to find out how much memory your current hosting plan permits. You may be able to find this on your provider’s website or in your hosting dashboard. Otherwise, contact your provider directly and they should be able to tell you.

If you’ve reached your site’s maximum memory limit but you’re still seeing the WordPress memory limit error, your only real option is to change your hosting. This may involve switching providers, upgrading to a higher tier, or opting for a different type of plan.

For those who started out on a shared hosting plan, it may be time to upgrade to a Virtual Private Server (VPS) or cloud hosting, both of which offer more space and resources. It’s also worth looking for a plan that’s flexible, where you can easily increase the amount of resources allocated to your site as needed.

Here at Kinsta, we offer managed WordPress hosting powered by the Google Cloud Platform:

How to resolve out of memory error in PHP?
Kinsta plans

Not only is it fast and secure but all of our plans set a default memory limit of 256 MB. For most sites, this should be more than enough. However, if you ever experience any memory-related issues on Kinsta, just reach out to our support team and we’ll help get you resolve the problem.

We even offer free migrations from many other WordPress web hosts. This means you can have your site moved to a new home and eliminate the WordPress memory limit error quickly.

Summary

It can be frustrating to encounter an error on your WordPress site, particularly if it doesn’t offer you much information. Fortunately, the WordPress memory limit error is more accommodating than most. It lets you know exactly what the problem is and from there the path to fixing it is pretty straightforward.

You have two main options when it comes to dealing with a PHP memory limit issue:

  1. Increase your site’s memory limit manually, using an SFTP client or a similar tool.
  2. Upgrade to a hosting plan that offers more resources for your site to use.

If you have any further questions about how to deal with this specific error or would like to know more about our free migrations, please reach out and our Customer Support will be happy to help you out!


Get all your applications, databases and WordPress sites online and under one roof. Our feature-packed, high-performance cloud platform includes:

  • Easy setup and management in the MyKinsta dashboard
  • 24/7 expert support
  • The best Google Cloud Platform hardware and network, powered by Kubernetes for maximum scalability
  • An enterprise-level Cloudflare integration for speed and security
  • Global audience reach with up to 35 data centers and 275 PoPs worldwide

Test it yourself with $20 off your first month of Application Hosting or Database Hosting. Explore our plans or talk to sales to find your best fit.

How do I fix out of memory error in PHP?

Upping Your PHP Memory Limit.
Using the same steps as above, we'll want to edit the php. ini file. Update the default memory_limit. ... .
Restart your apache server and terminal so the change will take effect. sudo apachectl restart..
Run your composer command again..

How do I fix PHP fatal error allowed memory size 134217728 bytes exhausted?

Re: Allowed memory size of 134217728 bytes exhausted You could try increasing this limit in your php. ini file. Look for memory_limit and set to something higher like memory_limit = 245M.

How to clear memory in PHP?

If you want to clear the memory then you can use unset or just put into another function then the variables will be cleared. Memory and performance go hand in hand, so it is useful to implement caching in your PHP application. You should not run same processes multiple times if possible. Same applies to sql queries.

What is fatal error out of memory in PHP?

This error indicates that there isn't enough PHP memory available on your server. The memory limit for a script should be set higher on your server, so please increase the PHP memory on your WP.