Step-by-Step Guide to Resolving the WordPress Memory Exhausted Error
The “Memory Exhausted” error is a common issue many WordPress users face, especially when running resource-intensive plugins or themes. This error typically appears as:
“Fatal error: Allowed memory size of X bytes exhausted (tried to allocate Y bytes) in /path/to/php/file.php.” . WordPress uses a certain amount of memory allocated by your server to execute PHP scripts. When the required memory exceeds the limit set by your hosting provider, the error occurs.
Common reasons include:
- Using a poorly coded plugin or theme.
- Running too many resource-heavy plugins.
- Large media files or a growing database.
How to Fix the WordPress Memory Exhausted Error
Step 1: Check Your Current PHP Memory Limit
Before increasing memory, check your current limit:
- Go to your WordPress admin dashboard.
- Navigate to Tools > Site Health > Info.
- Expand the Server section to view the memory limit.
If the limit is low (e.g., 32MB or 64MB), proceed to increase it.
Step 2: Increase the PHP Memory Limit in wp-config.php
The easiest way to fix the error is by increasing the memory limit in WordPress configuration.
- Access Your Website Files:
- Use an FTP client (e.g., FileZilla) or your hosting control panel’s File Manager.
- Locate the wp-config.php File:
- This file is in your WordPress root directory.
- Edit wp-config.php: Open the file and add the following line before */ That’s all, stop editing! Happy publishing. */**:
define('WP_MEMORY_LIMIT', '256M');
- Save the changes and upload the file back to the server.
Step 3: Adjust the Server’s PHP Configuration
If Step 2 doesn’t work, your hosting provider might have a server-level memory cap. You can try updating the PHP configuration file.
- Locate the php.ini File:
- This file is usually in your server’s root or a PHP directory. If it’s missing, create a new file named php.ini.
- Edit the File: Add or update this line:
memory_limit = 256M
- Save the file and upload it back.
Step 4: Modify the .htaccess File
If the above methods don’t work, update the .htaccess file.
- Access the .htaccess File:
- It’s in your WordPress root directory.
- Edit the File: Add this line at the end:
php_value memory_limit 256M
- Save and upload the file back.
Step 5: Disable Resource-Heavy Plugins or Themes
Sometimes, a specific plugin or theme causes excessive memory usage.
- Deactivate Plugins:
- Go to Plugins > Installed Plugins and deactivate all plugins.
- Reactivate them one by one to identify the culprit.
- Switch Themes:
- Go to Appearance > Themes and temporarily activate a default WordPress theme (e.g., Twenty Twenty-One).
Step 6: Contact Your Hosting Provider
If the error persists after trying all the steps, your hosting plan might not support higher memory limits. Contact your hosting provider and request an increase in PHP memory.
Conclusion
The WordPress memory exhausted error can be frustrating, but it’s relatively easy to fix with the steps outlined above. By increasing your PHP memory limit and optimizing your website, you can ensure your WordPress site runs smoothly without interruptions.
By choosing SternHost, you’re opting for premium domain registration, secure web hosting, and optimized WordPress hosting solutions designed for high performance and reliability. Let SternHost handle the backend, so you can focus on delivering a flawless experience to your audience. Get started today and empower your website with SternHost