Fatal error: Allowed Memory Size Error in WordPress
A fatal error related to allowed memory size in WordPress means your website is running out of allocated PHP memory to complete a task. This is a very common issue, and you can fix it by increasing the memory limit in your WordPress configuration file.
What Causes the Error?
The error message “Fatal error: Allowed memory size of X bytes exhausted” occurs when a script, plugin, or theme on your WordPress site tries to use more memory than is currently assigned to PHP. This can happen during:
- Plugin Activation or Updates: Some plugins require a lot of memory, especially during installation or updates.
- Image Uploads or Manipulation: Processing large images, creating thumbnails, or resizing them can be very memory-intensive.
- Running Complex Queries: Websites with a large amount of content or complex databases might hit this limit when running certain operations.
How to Fix the Error
You can fix this error by increasing the PHP memory limit in your WordPress configuration file.
Step 1: Access Your wp-config.php
File
- Log in to your hosting account and navigate to cPanel’s File Manager.
- Open the
public_html
directory, which is the root of your WordPress installation. - Find the file named
wp-config.php
.
Step 2: Edit the wp-config.php
File
- Right-click on the
wp-config.php
file and select Edit. - Add the following line of code just before the line that says
/* That's all, stop editing! Happy blogging. */
:PHPdefine( 'WP_MEMORY_LIMIT', '256M' );
This line tells WordPress to increase the memory limit to 256 megabytes, which is sufficient for most websites. You can increase this number if needed, but 256M is a good starting point.
- Click Save Changes in the top-right corner of the editor.
Alternative Methods
If editing wp-config.php
doesn’t solve the issue, you can try these other methods:
Editing the .htaccess
file
You can add a line to your .htaccess
file to increase the memory limit.
- In File Manager, find the
.htaccess
file in yourpublic_html
directory. - Add the following line at the very top or bottom of the file:
Apache
php_value memory_limit 256M
- Save the changes.
Editing the php.ini
file
This method requires you to have a php.ini
file in your root directory.
- Create a new file named
php.ini
in yourpublic_html
directory if one doesn’t exist. - Add the following line to the file:
Ini, TOML
memory_limit = 256M
- Save the changes.
If you are still experiencing the error after trying these steps, you may need to contact your hosting provider. Some shared hosting plans have a hard-coded memory limit that cannot be overridden by these methods.