How to Fix WordPress Memory Exhausted Error by Increasing PHP Memory Limit

How to Fix WordPress Memory Exhausted Error
Reading Time: 3 minutes

How to Fix WordPress Memory Exhausted Error by Increasing PHP Memory Limit

The “Memory Exhausted” error in WordPress can be frustrating, as it prevents your site from functioning properly. This error occurs when your site exceeds the allocated PHP memory limit. Fortunately, increasing the PHP memory limit is a straightforward process. This guide will walk you through the steps to fix the error and provide solutions to ensure it doesn’t happen again.

Understanding the Memory Exhausted Error

The “memory exhausted” error typically appears as:

Fatal error: Allowed memory size of X bytes exhausted (tried to allocate Y bytes)

This message indicates that a script or process on your WordPress site has used more memory than what’s allocated by the server. This can happen due to:

  • Large themes or plugins
  • High traffic on your site
  • Resource-intensive operations

Steps to Increase PHP Memory Limit

1. Edit the wp-config.php File

The wp-config.php file is the main configuration file for your WordPress site. Adding a line of code to this file can increase the PHP memory limit.

Steps:

  1. Access Your Site via FTP/SFTP or cPanel File Manager: Use an FTP client like FileZilla or your hosting provider’s file manager.
  2. Locate the wp-config.php File: This file is located in the root directory of your WordPress installation.
  3. Edit the File:
  • Open the wp-config.php file in a text editor.
  • Add the following line just before the line that says /* That's all, stop editing! Happy publishing. */: define('WP_MEMORY_LIMIT', '256M');
  • Save the file and upload it back to your server.

Example Code Snippet:

<?php
// Other configurations

define('WP_MEMORY_LIMIT', '256M'); // Increases memory limit to 256MB

/* That's all, stop editing! Happy publishing. */

2. Modify the php.ini File

The php.ini file is the main configuration file for PHP. Adjusting settings here can increase the memory limit for your entire site.

Steps:

  1. Access Your Site via FTP/SFTP or cPanel File Manager: You might need to use the file manager provided by your hosting provider if you don’t have access to the server.
  2. Locate the php.ini File:
  • If you don’t see php.ini, you can create one or check with your hosting provider for its location.
  1. Edit the File:
  • Open the php.ini file in a text editor.
  • Add or update the following lines: memory_limit = 256M
  • Save the file and upload it back to your server.

3. Update .htaccess File

If you’re on a server that uses Apache, you can also increase the memory limit by editing the .htaccess file.

Steps:

  1. Access Your Site via FTP/SFTP or cPanel File Manager.
  2. Locate the .htaccess File: This file is in the root directory of your WordPress installation.
  3. Edit the File:
  • Open the .htaccess file in a text editor.
  • Add the following line at the end of the file: php_value memory_limit 256M
  • Save the file and upload it back to your server.

4. Contact Your Hosting Provider

If the above methods don’t work or if you’re on a managed WordPress hosting plan, your hosting provider might have specific limits or restrictions.

Steps:

  1. Submit a Support Ticket:
  • Provide details about the memory exhaustion error and the steps you’ve taken.
  1. Request Assistance:
  • Ask your hosting provider to increase the PHP memory limit on your behalf.

Example Scenario: Fixing the Error

Imagine you encounter the “Memory Exhausted” error while trying to use a resource-heavy plugin on your WordPress site. Here’s how you might resolve it:

  1. Edit wp-config.php: You add define('WP_MEMORY_LIMIT', '256M'); to your wp-config.php file.
  2. Check Plugin Performance: You notice that a plugin is consuming excessive memory. You deactivate it and find a more optimized alternative.
  3. Update php.ini: You confirm that memory_limit is set to 256M in the php.ini file.
  4. Verify and Test: After making these changes, the error is resolved, and your site runs smoothly.

FAQs

Q1: How do I know if the memory limit increase has worked?
You can check your site’s functionality after applying the changes. Additionally, use a plugin like “WP Memory Usage” to monitor memory usage.

Q2: What if I can’t access php.ini or .htaccess?
If you can’t access these files, contact your hosting provider for assistance. They may be able to adjust the memory limit for you.

Q3: How can I prevent memory exhaustion in the future?
Regularly monitor your site’s performance, update plugins and themes, and use a caching plugin to optimize resource usage.

Q4: Will increasing memory limit affect my hosting plan?
Increasing the memory limit should not affect your hosting plan, but it’s always good to consult with your hosting provider to ensure compatibility with your plan.

Fixing the “Memory Exhausted” error in WordPress by increasing the PHP memory limit is a crucial step in maintaining your site’s performance. By following the methods outlined above—editing wp-config.php, php.ini, .htaccess, or contacting your hosting provider—you can resolve the issue and ensure that your site runs smoothly. Regular maintenance and monitoring will help you avoid similar issues and provide a better experience for your users.

If you’re facing the “Briefly Unavailable for Scheduled Maintenance error in WordPress, learn how to fix it quickly with this step-by-step guide.

Featured Image: vivago.ai

Share the Post:

Related Posts

Join Our Newsletter!

Scroll to Top

CONTACT US

Days :
Hours :
Minutes :
Seconds
Currently, we are only providing premium service. Contact us for more details!

Need a FREE WordPress Health Check Service!