How To Fix Fatal Error: Allowed Memory Size Exhausted in WordPress

How To Fix Fatal Error Allowed Memory Size Exhausted in WordPress

In this guide, learn how to increase WordPress memory limit on your site. Also see when it is best to find ways to reduce memory consumption, instead of increasing the wp memory limit

Your WordPress website needs computer memory to function. Sometimes, the memory allocated may not be enough to run your site and you will see a WordPress memory limit error like this:

fatal error: allowed memory size of 67108864 bytes exhausted

A second error that indicates low memory in WordPress is the White Screen of Death. If your site doesn’t function and all you see is a white screen, it is possibly because WordPress is running out of memory.

In this article, we explain what causes “Fatal Error: Allowed memory size of bytes exhausted in WordPress” and the simple steps you can take to fix it.

Content:

What Causes Fatal WordPress Memory Limit Error: Allowed Memory Size of Bytes Exhausted?

To fully grasp the nuances of the WordPress memory limit issue, it’s essential to start at the core—PHP. PHP, or Hypertext Preprocessor, is the backbone of WordPress. It’s a server-side scripting language designed to generate dynamic web pages.

When you interact with a WordPress site, whether by adding content, installing plugins, or simply navigating the site, PHP scripts are working tirelessly behind the scenes.

Why PHP Matters in WordPress

WordPress, at its heart, is a collection of PHP scripts. These scripts communicate with your website’s database to retrieve and display the content you see on your screen.

Every theme you activate and every plugin you install introduces more PHP scripts into the ecosystem, each demanding a slice of your server’s resources to function.

The Role of Memory Limits in PHP

PHP scripts require memory to execute. The memory limit in PHP is a safety mechanism that prevents any single script from consuming all available server resources, which could lead to degraded performance or even a total server shutdown.

This limit ensures that your hosting server can efficiently juggle multiple requests without compromising stability.

In a typical WordPress environment, the PHP memory limit dictates how much memory PHP scripts are allowed to use at any one time. Think of it as a budget allocated to PHP operations.

If the demands of your WordPress site exceed this budget due to heavy plugins, complex themes, or extensive multimedia content, the dreaded “memory exhausted” error rears its head.

Navigating Memory Limits

By default, WordPress tries to push the PHP memory limit to 64MB, but as your site grows, this may not suffice.

The error message you encounter is PHP’s way of saying, “I need more resources to complete this task.” It’s a cry for help, signalling that it’s time to reassess the allocated memory.

Increasing the PHP memory limit is akin to expanding the budget. It gives PHP scripts more breathing room to operate, but it’s not a carte blanche. It’s crucial to strike a balance between granting enough memory for smooth operation and maintaining optimal server performance.

Overallocation can lead to its own set of challenges, especially on shared hosting environments where resources are shared among multiple users.

The Bottom Line

Understanding PHP’s pivotal role in WordPress and the significance of memory limits is the first step toward effectively managing and troubleshooting memory-related issues.

By recognizing the interplay between PHP scripts and server resources, you’re better equipped to make informed decisions about your site’s infrastructure, ensuring a seamless and efficient WordPress experience.

How to Fix This WordPress Memory Limit Error

There are two basic ways to fix Fatal Error: Allowed Memory Size of Bytes Exhausted in WordPress. You can either increase the WordPress memory limit or get rid of the script that requires more memory. Check our beginners guide below:

Increase PHP Memory Limit in WordPress – the Easy Fix

As we stated already, this error indicates your site ran out of memory. The obvious way to fix this is by increasing the amount of memory that can be allocated to a script.

By design, WordPress first tries to increase your memory limit to 64 MB. Seeing this error indicates this size is still not enough, or in some cases, your server prevents the allocation of more memory.

You can manually increase memory limit in WordPress by editing the wp-config file.

To do this, connect to your site using FileZilla FTP Client. If you are not sure how to create the connection, watch this video: How To Use FTP.

When connected, your site folders and files will be displayed in the bottom right of your screen. Look for the folder containing all your WordPress files and double-click to open it.

Main WordPress folder - fix allowed memory size exhausted in WordPress

In this folder, locate your wp-config file, right-click on it, and click View/Edit.

Edit wp-config

When the file opens in your text editor, scroll towards the bottom to find the line that says “That’s all, stop editing! Happy blogging.” Paste the following code above that line.

define( ‘WP_MEMORY_LIMIT’, ‘128M’ )

Add code to increase PHP memory

Save this file and close the editor. FileZilla will prompt you to upload the edited file. Click Yes.

This will increase your WP memory limit to 128 Megabytes.

Now reload your site. The problem should be fixed and your site should display properly.

Note: The line we added above increased the memory to 128 megabytes. If you still get the WordPress memory limit error, then this memory size may still be insufficient. You can fix this by changing the PHP memory limit to 256M, or even 512M.

Alternate Solution – Find the Script Causing the Error

The fix above can help you quickly get out of this WordPress memory limit issue. But there are situations where it’s better to find the script that requires more memory and delete it.

If, for example, you need to increase the allocated memory above 256M, then that script is already taking too much memory. This could ruin your site performance.

In some cases, your host may not permit you to increase memory at all. If this is so for you, the quick fix above will not solve the issue. In this case, you can contact your host and ask them to increase the memory. Or better yet, you can track down the memory-hungry script and get rid of it.

The first place you want to look to find this script is your plugins. If you installed a WordPress plugin shortly before this error occurred, then that’s most likely the cause.

Read this article to see how to know if a plugin is the cause of your issue, and how to locate and delete the plugin: How To Disable WordPress Plugins Using FTP.

More often than not, a plugin would be responsible. If you, however, go through the steps to disable plugins and it doesn’t solve the problem, then the next place to look is your currently active theme. Read this post to learn how to find out if your theme is the cause of your WordPress memory issue, and how to fix it: How To Disable WordPress Theme Using FTP.

When addressing WordPress memory limits by modifying server files or tweaking settings, it’s imperative to tread carefully, as these actions carry inherent security implications. Ensuring the safety and integrity of your website during such technical adjustments is crucial.

Here, we delve into the best practices for securely making changes to server files, underlining the importance of cautious and informed modifications.

The Importance of Backups: Your Safety Net

Before embarking on any changes to your WordPress site’s core files or settings, establishing a robust backup protocol is non-negotiable. Backups serve as your safety net, allowing you to restore your site to its previous state in case of any missteps or unforeseen consequences arising from the modifications.

Utilize reputable WordPress backup solutions or your hosting provider’s backup services to create comprehensive backups of your site’s files and database. Regularly scheduled backups ensure you always have a recent snapshot to fall back on.

User Permissions: The Key to Controlled Access

User permissions play a pivotal role in maintaining your site’s security. When modifying server files or increasing memory limits, ensure that only users with the necessary expertise and trust level have access to perform these tasks.

Restricting file access to administrators or trusted developers helps mitigate the risk of accidental or malicious changes that could compromise your site’s functionality or security. Employ the principle of least privilege, granting users only the permissions they need to fulfill their roles.

Secure File Editing Practices

When direct modifications to server files are required, adopting secure file editing practices is essential.

  • Use Secure Connections: Always use secure FTP (SFTP) or SSH connections when accessing your server files remotely. These protocols encrypt the data transfer, protecting your credentials and modifications from interception.
  • Edit with Caution: When editing critical files like wp-config.php or .htaccess, make precise, well-understood changes. If possible, consult with a developer or utilize trusted resources to ensure the modifications achieve the desired outcome without introducing vulnerabilities.
  • Monitor Changes: Implementing file integrity monitoring can alert you to unauthorized modifications, enabling swift action to rectify any security breaches.

Staging Environments: Test Before You Implement

For significant changes or updates, employing a staging environment is highly advisable. A staging site is a clone of your live website where you can safely test modifications without impacting your live site’s functionality or user experience.

Once you’ve verified that changes, such as memory limit adjustments, function as intended without adverse effects, you can confidently apply them to your live site.

Stay Informed and Updated

Keeping abreast of best practices in WordPress management and security is invaluable. Regularly updating your WordPress core, themes, and plugins not only introduces new features and performance enhancements but also patches security vulnerabilities that could be exploited by attackers.

Embracing Long-Term Optimization Strategies for WordPress

Increasing the PHP memory limit can provide immediate relief from memory exhaustion errors. However, it’s akin to putting a bandage on a symptom rather than addressing the underlying causes. For sustainable website health and performance, adopting long-term optimization strategies is crucial.

These strategies not only help prevent memory issues but also contribute to faster loading times, improved user experience, and better search engine rankings.

Image Optimization: Keeping It Light

High-resolution images can significantly enhance the visual appeal of your site. However, they come with a cost, which is an increased load on server resources. Large image files require more memory to process, contributing to the memory limit being reached quickly.

The solution lies in image optimization: compressing images to reduce their file size without compromising quality. Tools like Adobe Photoshop, TinyPNG, or WordPress plugins such as WP Smush can automate this process. It ensures that your site remains visually appealing yet lightweight.

Caching: The Art of Remembering

Caching is a technique that temporarily stores copies of your site’s content in a cache, or a storage area, allowing subsequent requests for the same content to be served faster. Instead of generating a page from scratch every time, a cached version is presented, significantly reducing the load on your server and the memory used.

Implementing caching through plugins like W3 Total Cache or WP Rocket can dramatically improve your site’s performance and efficiency.

Plugin Prudence: Less Is More

Plugins extend the functionality of WordPress in almost limitless ways. However, each plugin adds to the load on your server’s memory. It’s tempting to install multiple plugins for various features, but this can lead to unnecessary strain on your resources.

The key is to be selective. Keep only the plugins that are essential to your site’s operation. Regularly review and deactivate or delete those that are not in use. Additionally, opt for high-quality plugins with good reviews and regular updates. These are more likely to be optimized for performance.

Theme Optimization: Choosing Wisely

Your WordPress theme can be a significant factor in your site’s memory consumption. Themes laden with features and complex visuals may require more resources to run smoothly.

When choosing a theme, look for one that strikes a balance between aesthetics and performance. Lightweight themes are designed with efficiency in mind, ensuring your site remains swift and responsive.

Regular Maintenance: Keeping Your Site in Top Shape

Just like any well-oiled machine, your WordPress site requires regular maintenance to operate efficiently. This includes updating WordPress, themes, and plugins to their latest versions. That’s because updates often include optimizations that improve performance and reduce memory usage.

Regularly cleaning up your WordPress database by removing unnecessary data such as spam comments, old revisions, and transient options can also help reduce the load on your server.

How Can You Use This Information

The steps covered in this guide can help you resolve the WordPress memory limit error. The quick fix (increasing WordPress memory) would be suitable in most cases.

However, if you are concerned about performance (e.g. the speed of your site), the better fix is finding the script that’s taking too much memory and getting rid of it. Our second solution would help you do this. You may also read our WordPress Speed Guide to learn how to increase your site speed.

Are you still seeing this error after going through all the steps? Then you may need professional help. Request our Premium WordPress Support Service and one of our programmers will get to work immediately and fix it for you.

Frequently Asked Questions (FAQs)

What is the WordPress memory limit?

The WordPress memory limit is the maximum amount of server memory that PHP scripts are allowed to consume while running WordPress. This limit ensures that scripts do not use more resources than allocated, preventing potential server performance issues.

Why am I encountering a WordPress memory limit error?

This error typically occurs when your WordPress site’s PHP scripts require more memory than the current limit set on your server. This can be due to resource-intensive plugins, themes, or large media files.

How can I check my current WordPress memory limit?

You can check your current memory limit by accessing your WordPress dashboard. Go to “Tools” > “Site Health” > “Info” tab, and look under the “Server” section. The PHP memory limit should be listed there.

Is increasing the WordPress memory limit safe?

Increasing the memory limit is generally safe if done correctly and within the capacity of your hosting server. However, it’s important to implement this change cautiously, adhering to best security practices like backups and proper user permissions.

How do I increase the WordPress memory limit?

You can increase the memory limit by editing the wp-config.php file and adding the line define(‘WP_MEMORY_LIMIT’, ‘256M’);. Alternatively, you can adjust it through the .htaccess file or the php.ini file, depending on your hosting environment.

Can increasing the WordPress memory limit affect website performance?

Properly increasing the memory limit can actually improve your website’s performance by allowing necessary scripts to run without interruption. However, excessively high limits without adequate server resources can lead to other performance issues.

What are some long-term strategies to avoid memory limit errors?

Optimizing your website by compressing images, using caching solutions, minimizing the number of active plugins, and choosing a suitable hosting plan are effective strategies to manage memory usage more efficiently.

Should I make changes to server files myself?

If you’re not confident in making these changes or understanding their implications, it’s advisable to consult with a professional developer. Also, contact your hosting provider’s support team to avoid potential issues.

How often should I back up my WordPress site?

Regular backups are crucial, especially before making any significant changes to your site. The frequency of backups should reflect how often your site’s content is updated. Daily backups are recommended for active sites.

Can optimizing images really help with the memory limit issue?

Yes, optimizing images reduces their file size, which in turn decreases the amount of memory required to load and display your site’s content. This can help in managing your site’s overall memory usage more effectively.

What should I do if I still encounter errors after increasing the memory limit?

If errors persist, it could indicate deeper issues related to specific plugins, themes, or server configurations. Consider deactivating plugins one by one to identify the culprit or consult with a WordPress specialist for a thorough analysis.

More Resources:

 This post was written by Mesheal Fegor

Mesheal Fegor is a Web/WordPress Developer and technical writer. His WordPress help articles have been featured on Kinsta and other sites. Mesheal holds a master's degree in computer science. His writing focuses on technical WordPress issues, ranging from core WordPress problems, to issues with WooCommerce, and more.

Last edited by: FixRunner Team