How To Fix Your WordPress Memory Exhausted Error- The Easy Way

Welcome to our step-by-step tutorial on how to increase WordPress memory limit. Here we described several ways to edit your WordPress files with a few lines of code. This helps to extend your site's maximum PHP memory limit and the maximum upload file size.

Running a multimedia-rich site may cause memory limit errors. Suppose you're trying to upload a new resource like a plugin or media file to your site and a message comes- “Fatal error: Allowed memory size of xxxxxx bytes exhausted”. Sometimes it may say- “filename.jpg exceeds the maximum upload size for this site.”

No worries, there are multiple ways to fix this issue. You can increase the PHP memory available on your WordPress website and continue to amplify your site functionalities without any issues.

Let's start from the basics-

WordPress PHP Memory Limit: What It is & Why It Matters

As you know, WordPress is written in PHP language. PHP is a server-side programming language.

PHP is capable to manage various attributes like processing WordPress interrogations & queries, calculations, and others. But it needs memory to perform these operations.

WordPress's default memory limit is 32MB. It works fine for sites with few static pages and a limited number of multimedia content and plugins. But as you start adding more plugins or other elements it requires more memory to accommodate.

Once you reach the maximum memory limit, WordPress will automatically increase available memory to 40MB for a single site and 64MB for a multisite. When you cross that it gives you the fatal error message. And you won't be able to add new content until you resolve the issue.

Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 2348617 bytes) in /home4/xxx/public_html/wp-includes/plugin.php on line xxx
OR
Fatal error: Allowed memory size of 41943040 bytes exhausted

You will see the error message when your WordPress requires more memory limit than the default allocated memory limitation.

Does PHP Memory Limit Relate to Performance?

You need to be careful when using plugins, themes, or other elements that require additional memory. Some web host providers keep the PHP memory limit extremely low. As a result, it may cause memory issues.

For example, 3 PHP scripts are using 100 MB of memory each at the same time. This means, collectively they require 300 MB of memory utilization. So, a PHP limit of 128 MB wouldn't be sufficient.

When you're running out of memory, your plugins stop working and the site isn't loading. You get the error message “Allowed memory size exhausted” and it keeps telling you to increase your PHP memory limit.

What Causes the “WordPress Memory Limit Exhausted” Error?

how to increase memory limit

At the begging of your WordPress journey, you probably choose a hosting plan with limited RAM due to reasonable prices. This type of plan includes a limited amount of resources with a certain RAM limit.

As your WordPress website grows, you need to upgrade the memory limit. Because with time the size of the database and the number of scripts and files also increase. Moreover, you may need plugins or themes that need extra memory to perform accordingly.

However, there could be other issues as well for this fatal error. It would not be a wise decision to up your limit without knowing the cause.

Here are some common reasons that may cause memory limit errors:

  • Web Server Limitation
  • Poor-Quality Plugins
  • Outdated PHP Versions
  • Memory-Hungry Media

Web Server Limitation

Web servers set a memory limit that can be assigned to a script. Since WordPress is made up of scripts written in PHP, limiting memory is crucial to protect servers.

Web servers need enough memory to run multiple applications simultaneously. And PHP can only be assigned some of the server's memory. If memory used by PHP scripts is not limited, a poorly written script can use the entire server memory. It may even crash the entire server. As a result, all sites on that server will be inaccessible.

Now, when one of your scripts needs more memory than the allocated limit, it runs out of memory. As a result, you'll get the WordPress Allowed memory size exhausted error.

Poor-Quality Plugins/Themes

Every plugin has its own purpose. For example, some plugins are used to increase site performance whereas others are designed to perform a particular function but don't pay attention to improving efficiency. Installing various plugins or themes with high memory requirements can max out available PHP memory.

Outdated PHP Versions

Running your WordPress site on outdated versions of PHP may cause certain security vulnerabilities, holes, bugs, etc. Search Engine Journal, 61.6% of WordPress sites are running outdated versions of PHP. That is the reason, a lot of WordPress sites are attacked by hackers every year. Also, with the older version, you may face a memory fatal error. On the other hand, the latest PHP versions are capable to manage more tasks in an organized way.

Read more: How to Check & Update Your PHP Version in WordPress.

Memory-Hungry Media

The large size of media files may cause your page to suffer a fatal error. If your WordPress site has only text with the occasional image and link, you have less chance to reach the memory limit. But when you're consistently uploading videos and other visual content, you may hit the memory limit.

How to Increase the PHP Memory Limit in WordPress

Before taking any action, you should check your current PHP memory limit. You can easily do that from your WordPress dashboard. For WordPress 5.2 or later, navigate to Tools → Site Health from your backend.

Under the Info tab, you'll find your PHP memory limit. If it's showing a lower value, you should increase it by editing your wp-config.php file.

Here are 5 different methods you can check-

  1. Edit your wp-config.php file
  2. Edit your PHP.ini file
  3. Configure your .htaccess file
  4. Use a memory increase plugin
  5. Contact your hosting provider

Method 01: Edit Your wp-config.php File

You need to be extremely careful when editing the wp-config.php file. As it includes all your base configuration details. You need a file transfer protocol (FTP) or SSH file transfer protocol (SFTP) service to enter your WordPress files.

The wp-config.php file is usually located in the root folder of your WordPress website with other folders like /wp-content/.

Find you wpconfigfile to increase WordPress memory limit

First, find the wp-config.php and download it by right-clicking on the file. Now, your FTP client will download it to your computer. Use a plain text editor program like Notepad or Text Edit to open and edit the file.

Open the wp-config.php file and look for this text string:

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

Next, replace the line with:

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

By modifying the second parameter you're telling WordPress to increase the PHP memory limit to 256MB.

Once you've done this, save the file and upload your wp-config.php file back to your server.

Method 02: Edit Your PHP.ini File

Edit your PHP.ini file

You can also increase the memory limit by editing your PHP.ini file. But remember, if you're using a shared hosting provider, it'll not allow you to modify the file. Instead, you can follow the next method. If you have access to PHP.ini, you'll most likely find it in the root folder. However, the file's location varies by host. 

To lift your memory limit from PHP.ini, follow the below steps-

  • Find your php.ini file. If you can't find it, alternatively you can create your own php.ini file. Save it in the WordPress installation’s root directory
  • Use an editor to open and edit your php.ini file
  • Search for the line with ‘memory limit = 32M'
  • Replace the 32M or some other number with the desired limit (e.g. 256M or 512M)
  • Save your changes and restart your localhost or server

Important Note: When you've built your own php.ini file, include the following line to it:

memory_limit = 256M (or 512M)

To keep yourself in the safe zone, update the max_execution_time too. This line defines the amount of time in seconds allotted for a PHP script to run. If the process exceeds the time limit, PHP gives an error. If you're planning to use more memory-intensive services and plugins, it would be better to increase this number. So, your script gets more time to run.

Clear your browser’s cookies before checking if the error has disappeared.

Method 03: Edit Your .htaccess File

If you find any difficulties in the above two methods, you can use the .htaccess file to increase your WordPress memory limit. The .htaccess file is a powerful website file that manages the high-level configuration of your website, including its memory limit.

The .htaccess file allows you to configure directories of the web server without modifying the main configuration file.

First, connect to your server using an FTP client. Next, go to your site's public_html directory that contains the .htaccess file:

Connect to your server using an FTP client

Now, open the file and write the following code snippet below the “#END WordPress” line:

php_value memory_limit 256M

After that, it may look like below-

Update your php memory limit

Don't forget to save once you're done with all the changes.

Method 04: Use a Memory Increase Plugin

If you don't have enough confidence to configure the above files or face any issues, simply use a plugin to increase your available PHP memory. Some powerful plugins for improving memory limit are:

These plugins help you to lift PHP memory without modifying configuration files. They work seamlessly with WordPress version 5.2 or higher.

Method 05: Contact Your Hosting Provider

Another possible solution could be to communicate with your host provider. They will suggest you the best solutions considering all circumstances.

If you don't want to get into the hassle of writing codes, then asking your hosting provider is the best option. They will take care of that for you.

Related Resource: 11 Things to Know Before Buying a Hosting Plan for Your Website.

Increase WordPress Memory Limit to Make Your Website Run Smoothly

Dealing with fatal errors in WordPress can be stressful for its users. Even inside an emergency moment, you may find yourself running out of room. It's better to check your memory limit on a regular basis especially when you're running a business site with a wide range of products and multi-media content.

However, the process largely depends on the hosting company you're using. You may take help from them to upgrade your memory limit. If you're running your site on cheap shared hosting, it may limit your ability to run your WordPress site in your desired way.

If you're struggling to choose the right WordPress hosting, check our famous guide on- Top 15 Reliable Managed Hosting for WordPress. It helps more than hundreds of businesses to take their businesses to a new height. Try your luck too!

Our comment section is open for any type of further inquiries.

Related Post

Sabirah Islam
Written by

Sabirah Islam

Sabirah Islam is a creative content writer who loves to work on diverse topics. She has a deep interest to work with new marketing strategies and different buyer persona. In free times she loves to play with her twin boys.

Have something to say? Cancel Reply

Your email address will not be published.

Table of Contents