How to Fix the PHP Fatal Error Allowed Memory Exhausted in WordPress

How to Fix the PHP Fatal Error Allowed Memory Exhausted in WordPress

The WordPress Allowed Memory Exhausted error is a condition where WordPress tries to use more PHP memory than the server allows, causing the process to stop and trigger a fatal error. The message usually reads [06-Sep-2025 13:09:17 UTC] PHP Fatal error: Allowed memory size of 41943040 bytes exhausted (tried to allocate 196608 bytes) or variations that refer to a small limit, such as 40 MB, that has been reached.

Causes of the WordPress Allowed Memory Exhausted Error

Before performing repairs, identify the cause of the memory usage so that the solution you implement is accurate and long-lasting. A combination of resource-heavy plugins, complex themes, large media files, and strict hosting limits is usually the main trigger for the WordPress Allowed Memory Exhausted error.

  • Heavy or unoptimized plugins like page builders, backup tools, or e-commerce plugins significantly increase memory usage.
  • Themes with various features and inefficient code increase the memory footprint and cause you to hit the limit faster.
  • High-resolution media and background processes like backups or indexing can trigger sudden spikes in memory usage.
  • Shared hosting plans often set a low memory_limit, which is quickly exhausted when traffic increases.

How to Fix the WordPress Allowed Memory Exhausted Error via wp-config.php

This is the easiest and most recommended method to increase the limit directly from the WordPress configuration. You will add a definition WP_MEMORY_LIMIT so that WordPress requests a larger portion of memory when running scripts.

  1. Access the File Manager in your hosting or via FTP, then open the file wp-config.php in the root of your WordPress installation, public_html.
  2. Add the line of code after this list, right above the sentence That’s all, stop editing Happy blogging
  3. Save and re-upload if using FTP, then try accessing your website to see if the error is gone.
define( 'WP_MEMORY_LIMIT', '512M' );define( 'WP_MAX_MEMORY_LIMIT', '512M' );

This method is effective in many cases, but the effective value is still limited by server policies, so it sometimes needs to be combined with settings at the hosting level.

How to Fix the WordPress Allowed Memory Exhausted Error via .htaccess

If your server is based on Apache with mod_php, you can increase the memory_limit via .htaccess to give PHP a higher limit at the server level. This method is suitable when editing wp-config.php has no effect because the server enforces a lower global limit.

Open or create the file .htaccess in the WordPress root, then add the following line before END WordPress and save your changes.

php_value memory_limit 512M

With .htaccess, the WordPress Allowed Memory Exhausted error is often resolved quickly, provided your server type supports this method. If you are using PHP FPM or NGINX, use php.ini or user.ini because .htaccess rules do not apply to those architectures.

How to Fix the WordPress Allowed Memory Exhausted Error via cPanel or php.ini

Many hosting providers offer PHP configuration directly in a panel like cPanel, allowing you to increase the memory_limit without touching application files. Alternatively, you can create or edit php.ini or user.ini to set a larger memory_limit.

  1. Log in to cPanel, open the MultiPHP INI Editor or the PHP Options menu, select your domain, and set memory_limit to 256M or 512M as needed.
  2. Save the changes and check your website again. Repeat the adjustments if the plugin and theme load still require more space.
  3. If this option is not available, contact your hosting provider to increase the limit on the server side so that the changes are truly active.

If you choose to update via the file php.ini, you can add or edit the following line.

memory_limit = 512M

Optimization After Fixing the WordPress Allowed Memory Exhausted Error

After the error is gone, perform optimizations so that memory usage is efficient and does not quickly hit the limit again when traffic or features increase. Focus on plugins, themes, media, caching, and routine updates to maintain memory.

  • Audit your plugins, deactivate unnecessary ones, replace heavy ones with lightweight alternatives, and update regularly.
  • Choose an efficient theme and avoid excessive features that are not being used.
  • Compress images, reduce excessive resolution, and enable caching to drastically lower the PHP load.
  • Update WordPress, themes, and plugins to get the latest performance improvements.

Prevent the WordPress Allowed Memory Exhausted Error from Recurring

Prevention provides long-term stability and reduces downtime due to the same error in the future. Monitoring, scheduling heavy tasks appropriately, and choosing a hosting plan that meets your needs will be very helpful.

  • Monitor memory usage with tools or monitoring plugins so you can take action before hitting the limit.
  • Schedule backups and scans during off-peak hours so that memory spikes do not interfere with busy times.
  • Consider upgrading your plan to one with more generous resources if your website's needs continue to grow and you have hit the local limit.
  • Optimize your database and use page and object caching to lower the execution load.

Written by

Muhammad Khoirun Nasikin

I enjoy tinkering with WordPress, hosting, VPS, web development, and various small experiments related to websites. I have over 3 years of experience in the web hosting industry.

COMMENTS

Loading...