Table of Contents
The WordPress memory exhausted error occurs when a script exceeds the default memory allocation limit for PHP. This can prevent your website from functioning correctly and result in an error message like “Fatal error: Allowed memory size of X bytes exhausted.” Increasing the PHP memory limit can often resolve this issue. Here’s how to do it:
Edit the wp-config.php File
The wp-config.php
file contains the base configuration details for your WordPress site. You can increase the PHP memory limit by adding a line of code to this file.
- Connect to your website using an FTP client or the file manager provided in your hosting control panel.
- Locate the
wp-config.php
file which is in the root directory of your WordPress installation. - Edit the file and add the following line of code just before the line that says
/* That's all, stop editing! Happy blogging. */
:
define('WP_MEMORY_LIMIT', '256M');
This line increases the PHP memory limit to 256MB. You can adjust the value based on your needs and the capabilities of your hosting environment.
- Save your changes and upload the file back to your server if you’re using FTP.
Edit the PHP.ini File
If editing the wp-config.php
doesn’t resolve the issue, you might need to increase the limit in the php.ini
file, which is the default configuration file for PHP.
- This file is usually not accessible on shared hosting, but you can create a file named
php.ini
in the root directory of your WordPress installation and add the following line:
memory_limit = 256M
- If you’re on a VPS or dedicated server and have access to the main
php.ini
file, you can directly edit this file with the same line. The location of this file can vary depending on your server configuration.
Edit the .htaccess File
Another way to increase the PHP memory limit is by editing the .htaccess
file located in the root directory of your WordPress installation.
- Access your site via FTP or file manager, and find the
.htaccess
file. - Edit the file and add the following line:
php_value memory_limit 256M
- Save your changes and check if the memory exhausted error is resolved.
Contact Your Hosting Provider
If none of the above solutions work, your hosting provider may not allow manual increases to the PHP memory limit. Contact their support team for assistance. They can either increase the limit for you or provide guidance on how to do it within their hosting environment.
Conclusion
Increasing the PHP memory limit can help resolve the memory exhausted error in WordPress. However, it’s also important to understand why the error occurred. It could be due to a poorly coded plugin, theme, or custom script. Consider deactivating plugins and switching to a default WordPress theme temporarily to diagnose the issue. If the problem persists, you may need to optimize your website or upgrade your hosting plan to accommodate your site’s requirements.