memory limit

How to fix memory exhausted error WordPress: 3 Methods to Increase PHP Memory

Share & Earn
70 / 100

What is the “WordPress Memory Exhausted” Error?

The “WordPress memory exhausted” error occurs when WordPress tries to use more memory than the default limit set by your web server. This often results in the following message:

Fatal error: Allowed memory size of X bytes exhausted (tried to allocate Y bytes) in /path/to/php/file on line Z

This error typically shows up when running resource-intensive plugins, themes, or custom scripts on your WordPress site.

Why Does This Error Happen?

WordPress, like any software, uses memory to run various tasks. The default PHP memory limit provided by many hosting providers is often set to 64MB or 128MB, which may not be enough if:

  • You have a large number of plugins installed.
  • You are using resource-intensive plugins (like WooCommerce, Elementor, or page builders).
  • Your site has a large database or extensive media library.
  • Themes with complex features consume more resources.
  • You are running multiple custom scripts or APIs.

When WordPress runs out of memory, it can’t complete its tasks, leading to the memory exhausted error.

How to Fix the Memory Exhausted Error in WordPress?

The most effective way to resolve this issue is by increasing the PHP memory limit allocated to your WordPress website. Here are several methods you can use to fix this issue.

Method 1: Increase Memory Limit via wp-config.php

One of the most common and simple ways to fix this error is by increasing the memory limit through the wp-config.php file.

  1. Access Your Site Files: Use an FTP client (like FileZilla) or your hosting control panel (like cPanel or Plesk) to access your WordPress files.
  2. Edit the wp-config.php file:
    • Locate the wp-config.php file in the root directory of your WordPress installation.
    • Open it for editing.
  3. Add the following code above the line that says /* That's all, stop editing! Happy publishing. */:
define( 'WP_MEMORY_LIMIT', '256M' );
  • This line of code increases the PHP memory limit to 256MB.

4. Save the file and re-upload it to your server if using FTP.

    Example:

    <?php
    // Other configurations
    
    // Increase memory limit to 256MB
    define( 'WP_MEMORY_LIMIT', '256M' );
    
    // That's all, stop editing! Happy publishing.

    After adding this line of code, the memory limit for WordPress should increase to 256MB, which is usually enough for most websites.

    Method 2: Modify the php.ini File

    If the wp-config.php method doesn’t work, you can also try modifying your php.ini file. This file controls the PHP configuration settings on your server.

    1. Access Your PHP Configuration: Using an FTP client or hosting control panel, locate the php.ini file. This is typically found in the root folder of your website or the public_html directory.
    2. Edit the php.ini file:
      • If the php.ini file does not exist, you can create one.
    3. Increase the memory limit: Add the following line to the php.ini file:iniCopy codememory_limit = 256M This sets the PHP memory limit to 256MB.
    4. Save the file and upload it to your server.

    Example:

    memory_limit = 256M

    If your server allows the use of a php.ini file, this will increase the memory limit and resolve the error.

    Method 3: Edit .htaccess File

    Another option is to increase the PHP memory limit via the .htaccess file. This file is usually hidden, but you can access it using FTP or your hosting control panel.

    1. Access the .htaccess File:
      • If it’s hidden, enable the option to view hidden files in your FTP client or file manager.
    2. Edit the .htaccess File:
      • Add the following line at the top of the .htaccess file:
    php_value memory_limit 256M

    3. Save the file and re-upload it to your server.

      Example:

      # BEGIN WordPress
      
      php_value memory_limit 256M
      
      # Other .htaccess rules for WordPress

      This will increase the memory limit through the server’s .htaccess configuration.

      Method 4: Contact Your Hosting Provider

      If none of the above methods work, it could mean your hosting provider has set a hard memory limit on the server that you cannot override. In this case, you should contact your hosting support team and ask them to increase your PHP memory limit. You can also Hire Website developers that will solve your issue.

      Verifying the Solution

      To check if the issue is resolved, try:

      • Reloading your website.
      • Visiting the page where the error previously occurred.
      • Deactivating and reactivating plugins/themes to see if the issue persists.

      Best Practices

      • Limit Plugins: Too many active plugins can overload the memory limit, so deactivate unnecessary plugins.
      • Optimize Images: Use compressed or optimized images to reduce memory consumption.
      • Choose Lightweight Themes: Some themes are heavy on resources. Consider switching to a more lightweight theme.
      • Monitor Resource Usage: Use tools or plugins like Query Monitor to see how much memory your site is consuming.

      Conclusion

      The “WordPress memory exhausted” error can be resolved easily by increasing the PHP memory limit using one of the methods above. Whether through wp-config.php, php.ini, or .htaccess, this will allocate more memory for your WordPress site, allowing it to handle larger tasks and plugins without running into memory issues. Make sure to monitor your site’s performance and optimize its usage to avoid future memory exhaustion problems.

      Please give us feedback or errors list so that we can help you to solve your issues and trying to give better results..