Memory Exhausted Error in WordPress is a common issue that arises when WordPress exceeds the default PHP memory limit allocated by your server.
This error typically appears as a “Fatal Error: Allowed memory size of X bytes exhausted” shows message for memory exhausted error, and it prevents your site from functioning properly.
This guide provides a comprehensive explanation of the problem, its causes, and detailed solutions to fix it.
Table of Contents
What Causes the WordPress Memory Exhausted Error?
- PHP Memory Limit: The server allocates a limited amount of memory for executing PHP scripts. If your WordPress site exceeds this limit, the error occurs.
- Resource-Intensive Plugins or Themes: Heavy plugins or poorly optimized themes can consume significant memory.
- Large Database Queries: Extensive or inefficient database queries can strain server resources.
- Image Processing: Uploading or processing large images can deplete memory.
- Increased Traffic: High traffic spikes demand more server resources, potentially causing memory issues.
How to Fix the WordPress Memory Exhausted Error
1. Increase PHP Memory Limit
Increasing the PHP memory limit is the most effective solution.
Step 1: Edit the wp-config.php File
- Access your site’s files via an FTP client or your hosting file manager.
- Locate the
wp-config.php
file in the root directory. - Add the following code before the line
/* That’s all, stop editing! Happy publishing. */
define('WP_MEMORY_LIMIT', '256M');
- This sets the memory limit to 256MB. You can adjust the value based on your hosting plan.
Step 2: Verify Changes
- Reload your website to check if the error is resolved.
- If the error persists, proceed to server-level changes.
2. Modify the php.ini File
The php.ini
file controls PHP configuration settings. Increasing the memory limit here ensures the server recognizes the change.
Step 1: Locate the php.ini File
- Access your server via FTP or your hosting control panel.
- Navigate to the root directory or the folder specific to your site.
Step 2: Increase Memory Limit
- Add or modify the following lines in the
php.ini
file
memory_limit = 256M
- Save the changes and restart the webserver if required.
Step 3: Test the Website
- Visit your site to confirm the error is resolved.
3. Update the .htaccess File
If you cannot access the php.ini
file, you can update the .htaccess
file to increase the memory limit.
Step 1: Locate the .htaccess File
- The
.htaccess
file is located in your site’s root directory. - Enable hidden files in your FTP client or file manager if it’s not visible.
Step 2: Add Memory Limit Code
- Add the following line at the top of the
.htaccess
file
php_value memory_limit 256M
Step 3: Save Changes
- Save the file and refresh your site to see if the error persists.
4. Deactivate Resource-Intensive Plugins
Some plugins consume significant memory, leading to exhaustion errors.
Step 1: Deactivate Plugins
- Go to Plugins > Installed Plugins in your WordPress dashboard.
- Deactivate all plugins.
Step 2: Reactivate Plugins One by One
- Reactivate each plugin individually while testing your site to identify the problematic plugin.
Step 3: Replace the Plugin
- Replace the problematic plugin with a lighter alternative or contact the plugin developer for optimization.
5. Switch to a Default Theme
Some themes are resource-intensive due to poorly optimized code.
Step 1: Activate a Default Theme
- Go to Appearance > Themes.
- Activate a default WordPress theme like Twenty Twenty-Three.
Step 2: Test the Site
- Check if the error persists. If resolved, contact your theme developer for support.
6. Optimize Your WordPress Site
Reducing unnecessary resource consumption can help prevent memory exhausted error.
Step 1: Clean Your Database
- Use plugins like WP-Optimize or Advanced Database Cleaner to remove:
- Unused data.
- Post revisions.
- Expired transients.
Step 2: Minimize Plugin Usage
- Deactivate and delete plugins you no longer use.
- Avoid redundant plugins with overlapping functionalities.
Step 3: Optimize Images
- Compress images using plugins like Smush or ShortPixel to reduce server load.
Step 4: Use a Caching Plugin
- Install a caching plugin like WP Rocket or W3 Total Cache to reduce server requests and improve performance.
7. Upgrade Your Hosting Plan
If your site has outgrown your current hosting plan, upgrading to a more robust solution may resolve memory-related issues.
Step 1: Assess Current Hosting Resources
- Check the PHP memory limit and server resources provided by your hosting plan.
Step 2: Upgrade Hosting
- Consider moving to:
- Managed WordPress Hosting: Optimized for WordPress, offering higher memory limits.
- VPS or Dedicated Hosting: Provides more server resources compared to shared hosting.
Step 3: Migrate to a Reliable Host
- If your current host cannot meet your needs, consider migrating to providers like SiteGround, WP Engine, or Kinsta.
8. Debug and Identify the Root Cause
If the issue persists, debug your site to find the root cause.
Step 1: Enable Debugging
- Add the following code to your
wp-config.php
file
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
Check the debug log (/wp-content/debug.log
) for errors related to memory exhausted error.
Step 2: Analyze Logs
- Review server error logs or PHP error logs for additional insights.
Step 3: Seek Professional Help
- Contact a WordPress developer or your hosting support for advanced troubleshooting.
Preventing WordPress Memory Exhausted Error
- Regular Updates:
- Keep WordPress core, themes, and plugins up to date to ensure optimal performance.
- Optimize Regularly:
- Clean your database and optimize images periodically.
- Monitor Resource Usage:
- Use tools like Query Monitor to track memory usage and identify bottlenecks.
- Choose Lightweight Themes and Plugins:
- Avoid bloated themes or plugins with unnecessary features.
- Enable Automatic Backups:
- Use backup plugins like UpdraftPlus to safeguard your site during maintenance.
Conclusion
The WordPress Memory Exhausted Error is a common but solvable problem that stems from resource limitations.
By following the solutions outlined in this guide, you can effectively increase the PHP memory limit, optimize your site, and prevent the issue from recurring.
Regular maintenance, resource monitoring, and choosing the right hosting plan are key to maintaining a smooth-running WordPress site.