Encountering a memory exhausted error in WordPress can be a daunting experience. This error typically occurs when a WordPress script exceeds the default PHP memory limit, disrupting site functionality and preventing access. Fortunately, increasing the PHP memory limit is a straightforward process that can resolve this issue, ensuring your WordPress site runs smoothly. This guide will walk you through the steps to increase your PHP memory limit, effectively solving the memory exhausted error.
Understanding the Memory Exhausted Error
The memory exhausted error often appears as a fatal error message stating, “Allowed memory size of XXXXXX bytes exhausted,” followed by the file path causing the error. This message indicates that a specific script has surpassed the allocated memory limit, leading to a halt in execution.
Steps to Increase PHP Memory Limit
1. Modify the wp-config.php File
One of the most effective methods to increase the PHP memory limit is by editing the
- Access Your Site Files: Use an FTP client or your hosting account’s file manager to access your WordPress site’s files.
- Edit wp-config.php: Locate the
wp-config.phpfile in the root directory. Open it in a text editor.
- Increase Memory Limit: Add the following line of code within the main PHP tags:
This line increases the PHP memory limit to 256MB, which should suffice for most WordPress sites. Adjust the value accordingly based on your needs and host’s policies.
2. Update the PHP.ini File
wp-config.php doesn’t resolve the error, you might need to edit the
php.ini file directly. This file is the default configuration file for PHP and controls many PHP settings.
- Locate PHP.ini: This file is usually found in the root directory or within a folder named
phpin your server’s file system. Access might vary based on your hosting environment.
- Edit PHP.ini: Look for the line
memory_limitand change its value:
memory_limit = 256M
- Save Changes: After editing, save the file and re-upload it if necessary.
3. Modify the .htaccess File
Another approach involves editing the
.htaccess file, especially if you don’t have access to
- Access .htaccess: Find the
.htaccessfile in the root directory of your WordPress installation.
- Increase Memory Limit: Add the following line at the end of the file:
php_value memory_limit 256M
- Save and Upload: Save your changes and ensure the file is correctly uploaded back to your server.
Increasing the PHP memory limit in WordPress can effectively resolve the memory exhausted error, improving your site’s performance and stability. While the
wp-config.php method is generally the most straightforward, you might need to explore alternative approaches depending on your hosting environment and access permissions. Always back up your site before making any changes to critical files like
.htaccess. If you’re unsure about making these changes yourself, consider reaching out to your hosting provider for assistance.