WordPress Memory Exhausted Error How to Fix

WordPress Memory Exhausted Error How to Fix
One of the most common issues WordPress users face is the Memory Exhausted Error, which usually appears as:
“Fatal error: Allowed memory size of X bytes exhausted (tried to allocate Y bytes)”
This error occurs when your WordPress website exceeds the default memory limit set by your server. It can cause your website to slow down, malfunction, or even crash. Fortunately, increasing your PHP memory limit is a straightforward process. Below is a detailed guide to help you fix this issue.
Step 1: Increase Memory Limit in wp-config.php
The easiest and most effective way to fix the memory exhausted error is by increasing the memory allocation in WordPress.
Steps:
- Access your website’s files:
You can access your site’s files using an FTP client (such as FileZilla) or through your hosting provider’s File Manager (like cPanel). - Locate the
wp-config.php
file:
This file is located in the root folder of your WordPress installation. Once you locate it, open the file for editing. - Add the memory limit line:
Insert the following line of code just before the line that says “That’s all, stop editing! Happy publishing.”:This code increases the PHP memory limit to 256MB. You can adjust this value as needed, but 256MB is generally enough for most websites.
- Save your changes:
After adding the code, save the file and upload it back to your server if you’re using FTP. - Check your website:
Visit your website to see if the error is resolved. If the site loads correctly, the issue was due to insufficient memory.
Step 2: Increase Memory Limit in php.ini
If modifying the wp-config.php
file didn’t work, the issue might be related to the server settings. Many servers limit the amount of memory available to WordPress through the php.ini
file.
Steps:
- Locate or create the
php.ini
file:
Thephp.ini
file is typically found in your site’s root folder, but if it’s not there, you can create one. - Edit the
php.ini
file:
Open thephp.ini
file and look for the line that sets the memory limit. If you can’t find it, you can add the following line:This will set the PHP memory limit to 256MB.
- Save and upload the file:
After editing or creating thephp.ini
file, save the changes and upload it back to your server. - Test your website:
Refresh your site to see if the error has been fixed.
Step 3: Modify .htaccess
(Alternative Method)
If modifying the php.ini
file isn’t an option (some shared hosting services don’t allow this), you can try increasing the memory limit via the .htaccess file.
Steps:
- Access the
.htaccess
file:
This file is located in the root directory of your WordPress installation. If you can’t see it, make sure that your FTP client is set to display hidden files. - Add the memory limit code:
Insert the following line at the top of the.htaccess
file: - Save the file:
After adding the code, save the file and upload it back to the server if needed. - Check your website:
Refresh your site to ensure the memory exhausted error is gone.
Step 4: Deactivate Plugins and Themes
If increasing the memory limit doesn’t solve the problem, the error may be caused by a plugin or theme consuming too much memory.
Steps:
- Deactivate all plugins:
Temporarily disable all plugins to see if one of them is causing the issue. You can deactivate plugins by going to your WordPress dashboard or renaming the plugins folder via FTP. - Activate plugins one by one:
Reactivate each plugin one by one, checking the website after each activation. This will help identify if a specific plugin is causing the memory issue. - Switch to a default theme:
If no plugin is at fault, try switching to a default WordPress theme (e.g., Twenty Twenty-Three) to rule out theme-related memory problems. - Fix or replace the problem plugin/theme:
Once you identify the plugin or theme causing the issue, consider replacing it or contacting the developer for support.
Step 5: Contact Your Hosting Provider
If none of the above solutions work, the problem might be with your hosting provider’s server configuration. Some hosting services place strict limits on memory usage that you cannot override on your own.
Steps:
- Contact your hosting provider:
Get in touch with your web host’s support team and ask them to increase your PHP memory limit. - Ask for a higher memory limit:
Request at least 256MB or more, depending on the complexity of your site. - Consider upgrading your hosting plan:
If your site is using more memory than allowed by your hosting plan, you might need to upgrade to a higher plan that offers more resources (e.g., from shared hosting to VPS or dedicated hosting).
Conclusion
The WordPress Memory Exhausted Error is a common issue that can disrupt your website, but it’s relatively easy to fix by increasing the PHP memory limit. Start by editing the wp-config.php
file, and if that doesn’t work, try modifying the php.ini
or .htaccess
files. If all else fails, deactivate plugins and themes or contact your hosting provider for assistance.
By following these steps, you should be able to resolve the error and improve your website’s performance.