- sunsoft.pk
- February 27, 2024
This is a frequently encountered WordPress error, and you can swiftly resolve it by expanding the PHP memory limit in your WordPress configuration.
In this guide, we will demonstrate the steps to address the WordPress memory exhausted error by adjusting the PHP memory limit.
What Is the WordPress Memory Exhausted Error?
WordPress is developed using PHP, a server-side programming language. Additionally, every website requires a WordPress hosting server to operate effectively.
Similar to any other computer, web servers need a specific amount of memory to run multiple applications simultaneously. Server administrators allocate distinct memory sizes to various applications, including PHP.
When your WordPress code demands more memory than the default allocation, you’ll encounter this error message:
Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 2348617 bytes) in /home4/xxx/public_html/wp-includes/plugin.php on line xxx
Memory exhausted error displayed on a WordPress site
Your WordPress site might be surpassing its allocated server memory if it contains:
- A large number of images, videos, and other media types
- Numerous inactive WordPress plugins
- Outgrown its hosting plan resources
By default, WordPress attempts to increase the PHP memory limit if it’s less than 64MB. However, 64MB is often insufficient.
With that said, let’s explore how to easily raise the PHP memory limit in WordPress to prevent the memory exhausted error.
How to Increase the PHP Memory Limit in WordPress
There are various methods to increase the PHP memory limit. One involves editing the wp-config.php file, another requires adjustments to the .htaccess file, and the final method entails checking the php.ini file.
Let’s walk through each one:
Editing the wp-config.php File
To start, you must edit the wp-config.php file on your WordPress site. This file is a core component located in your WordPress site’s root directory, commonly named public_html.
You’ll need to use an FTP client like FileZilla or the file manager in your web hosting control panel.
Next, paste the following line in the wp-config.php file just before the line that says, ‘That’s all, stop editing! Happy blogging.
define( 'WP_MEMORY_LIMIT', '256M' );
This code instructs WordPress to increase the PHP memory limit to 256MB.
For more detailed instructions, refer to our comprehensive guide on locating and editing the wp-config.php file.
Once you’ve completed the edit, save the changes and upload your wp-config.php file back to the server.
Now, visit your WordPress site, and the memory exhausted error should be resolved.
Editing the .htaccess File
The next method involves editing the .htaccess file, which is also situated in the root folder of your WordPress website.
Here, you should paste the following code before the line that reads #END WORDPRESS.
php_value memory_limit 256M
Similar to the previous code, this snippet instructs WordPress to raise the PHP memory limit to 256MB.
After making these changes, save the file and upload it back to your web server. Visit your WordPress website again to check if the memory limit error persists.
If you encounter difficulty locating the .htaccess file, refer to our guide on why the .htaccess file may be missing and how to find it.
Checking Your php.ini File
If the aforementioned methods prove ineffective, consider inspecting your php.ini file.
The php.ini file governs PHP settings, encompassing the PHP version and scripts. Typically managed by your hosting provider, it’s not a core WordPress file.
Review the code in php.ini to identify your PHP memory usage limit. Consult our guide on finding and editing the php.ini file for more information.
Given that this is an advanced approach, we recommend reaching out to your web hosting provider’s support team to explore the possibility of manually increasing the WordPress memory limit. Attempting this without proper expertise may lead to additional errors.