Skip to content

Fix WordPress Memory Exhausted Error: Step-by-Step Guide

WordPress Memory Exhausted Error

Fix WordPress Memory Exhausted Error: Step-by-Step Guide

Anyone has come across that dreadful error message saying that “WordPress memory exhausted error” while working on the website?You’re not alone. This is something which everyone can come across and experience to abrupt the progress or can make the situation irritated especially if the person is web developer or a WordPress user in a quest to maximize the site. Fortunately, it is not very difficult to remedy this issue. Today, we will help you to set up the memory limit for PHP to make your WordPress website function properly. This post will include the outlined breakdown, informed rationale of why it happens, and helpful tips on avoiding its repetition.

Understanding the WordPress Memory Exhausted Error

What is the WordPress Memory Exhausted Error?

The “WordPress memory exhausted” error appears when your website’s PHP memory limit is maxed out. Essentially, WordPress can’t allocate more memory to run your site’s scripts, which leads to an error message. This error typically looks something like this:

“Fatal error: Allowed memory size of X bytes exhausted in /path/to/your/file.php on line Y.”

Why Does This Error Occur?

Several reasons can cause the memory exhausted error. Firstly, your website may have grown over time, requiring more resources to handle its operations. Secondly, certain themes or plugins may consume more memory than others, pushing your PHP limits. Lastly, an improperly configured server may allocate insufficient memory, leading to this issue.

The Impact on Your Website

When your WordPress site encounters this error, it can significantly disrupt your site’s functionality. Pages might load slower, plugins may stop working, and you could even experience complete downtime. For web developers, this can mean lost productivity and unhappy clients.

Checking Your Current PHP Memory Limit

How to Check Your PHP Memory Limit

Before you increase your PHP memory limit, it’s essential to know the current limit set on your server. You can do this by accessing your WordPress dashboard and navigating to “Tools” > “Site Health.” Here, you’ll find detailed information about your server, including memory usage.

Using PHP Info

Another method to check your PHP memory limit is by creating a phpinfo.php file. Simply create a new file with the following content:

<?php phpinfo(); ?>

Upload this file to your server’s root directory and access it via your browser. This will display a page with various PHP settings, including the memory limit.

Understanding the Results

Once you’ve checked your current PHP memory limit, you’ll have a clear idea of how much memory is allocated and whether increasing it is necessary. Most often, the default memory limit is set to 64MB, which might not be sufficient for complex WordPress sites.

Increasing PHP Memory Limit via wp-config.php

Editing the wp-config.php File

One of the simplest ways to increase your PHP memory limit is by editing the wp-config.php file in your WordPress directory. Using an FTP client or your hosting provider’s file manager, locate the wp-config.php file and open it for editing.

How to Locate wp-config.php

Finding the wp-config.php file is a straightforward process, but it requires access to your site’s files either through an FTP client or your hosting provider’s file manager. Here are the steps to locate the wp-config.php file:

  1. Accessing Your Site via FTP:
    • Download and install an FTP client like FileZilla
    • Open the FTP client and enter your site’s FTP credentials (these are usually provided by your hosting provider).
    • Once connected, navigate to the root directory of your WordPress installation. This directory often contains folders like `wp-admin`, `wp-content`, and `wp-includes`.
    1. Using Your Hosting Provider’s File Manager:
    • Log in to your hosting provider’s control panel (cPanel, Plesk, etc.).
    • Look for a section called “File Manager” or something similar.
    • Navigate to the root directory of your WordPress site. Like with FTP, this will be the directory that houses the `wp-admin`, `wp-content`, and `wp-includes` folders.
    1. Locating wp-config.php:
    • In the root directory, you should see a file named `wp-config.php`.
    • This file is crucial as it contains your site’s database configuration and other important settings.

    Remember, always create a backup of your wp-config.php file before making any changes. This ensures that you can restore the original settings if anything goes wrong during the editing process.

Adding the Memory Limit Code

Add the following line of code before the line that says “That’s all, stop editing! Happy blogging.”:

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

This sets the PHP memory limit to 256MB. Save your changes and upload the file back to your server.

Verifying the Changes

After making these changes, revisit your site health page or phpinfo.php file to confirm the updated memory limit. If the changes are reflected, your site should now have a higher memory allocation, reducing the chances of encountering the memory exhausted error.

Increasing PHP Memory Limit via php.ini

Accessing the php.ini File

The php.ini file is where your server’s PHP configuration settings are stored. To increase your PHP memory limit using this file, you’ll need access to your server’s root directory. If you’re using shared hosting, you might have limited access, so contacting your hosting provider for assistance could be necessary.

Editing the php.ini File

Once you have access, locate the php.ini file and open it for editing. Find the line that specifies the memory limit:

“`

memory_limit = 64M

“`

Change this value to your desired memory limit, for example:

“`

memory_limit = 256M

“`

Saving and Restarting the Server

Save the changes and restart your web server to apply the new settings. This step ensures that the updated memory limit takes effect. After restarting, verify the changes using the methods mentioned earlier.

Increasing PHP Memory Limit via .htaccess

Understanding the .htaccess File

The .htaccess file is a configuration file used by Apache servers to manage server behavior. You can also use it to increase your PHP memory limit. This method is useful if you don’t have access to the php.ini file.

Locating the .htaccess File in cPanel

To increase your PHP memory limit using the .htaccess file, you first need to locate this file within your hosting account’s file structure. Here’s how to find it in cPanel:

  1. Log into cPanel:
    • Access your hosting account’s cPanel by logging in with your credentials.
    1. Navigate to File Manager:
    • In the main cPanel dashboard, locate and click on the File Manager icon. This section allows you to manage all the files on your server.
    1. Browse to Your Root Directory:
    • In the File Manager, navigate to the root directory of your WordPress installation. This is typically the `public_html` folder for your primary domain or a sub-directory if it’s an add-on domain.
    1. Locate the .htaccess File:
    • The .htaccess file is usually located in the root directory alongside folders such as `wp-admin`, `wp-content`, and `wp-includes`. If you don’t see the .htaccess file, make sure you’ve enabled the option to show hidden files. To do this, click on Settings in the top-right corner of the File Manager and check the Show Hidden Files (dotfiles) option.
    1. Edit the .htaccess File:
    • Once located, right-click on the .htaccess file and select Edit to open it in cPanel’s text editor. You can now add the necessary code to increase your PHP memory limit.

    Remember to create a backup of your .htaccess file before making any changes—to ensure that you can revert to the original if anything goes wrong.

Editing the .htaccess File

Locate the .htaccess file in your WordPress directory and open it for editing. Add the following line of code at the beginning or end of the file:

“`

php_value memory_limit 256M

“`

This instructs the server to allocate 256MB of memory for PHP scripts.

Verifying the Changes

Save the changes and upload the file back to your server. As always, verify the new memory limit by checking your site health page or phpinfo.php file. If the changes are reflected, your increased memory limit should reduce the likelihood of encountering the memory exhausted error.

Dealing with Persistent Memory Issues

  • Identifying Memory-Hogging Plugins
    If increasing your PHP memory limit doesn’t resolve the issue, it’s possible that one or more plugins are consuming excessive memory. Deactivate all your plugins and reactivate them one by one while monitoring your memory usage. This will help you identify the culprit.
  • Optimizing Your Database
    A cluttered database can also contribute to memory issues. Regularly clean up your WordPress database by removing unnecessary data such as post revisions, spam comments, and unused tables. Plugins like WP-Optimize can automate this process for you.
  • Consulting Your Hosting Provider
    If you’ve exhausted all troubleshooting steps and still experience memory issues, it might be time to consult your hosting provider. They can offer insights into server configurations and suggest upgrades if necessary.

Preventing Future Memory Exhausted Errors

Regularly Monitor Your Site

Keep an eye on your site’s performance and memory usage. Tools like New Relic and Query Monitor can help you track resource consumption and identify potential issues before they escalate.

Update Themes and Plugins

Ensure your themes and plugins are always up to date. Developers frequently release updates that include performance improvements and bug fixes, which can help prevent memory issues.

Choose a Reliable Hosting Provider

Investing in a reliable hosting provider can significantly impact your site’s performance. Look for providers that offer scalable resources, excellent customer support, and good uptime guarantees.

Conclusion

Encountering the “WordPress memory exhausted” error can be frustrating, but with the right approach, you can resolve it quickly. By understanding the causes, increasing your PHP memory limit, and following best practices to prevent future issues, you can ensure your WordPress site runs smoothly. Remember, a well-optimized site not only improves user experience but also boosts your SEO efforts.

If you’re looking to further enhance your WordPress skills, consider exploring our other blog posts and resources. Stay proactive, keep learning, and you’ll master the art of website management in no time. Happy blogging!

Hire Us

Recommended Posts

No comment yet, add your voice below!


Add a Comment

Your email address will not be published. Required fields are marked *

Shopping cart