Fix WordPress Memory Exhausted Error [Increase PHP Limit]

Fix WordPress Memory Exhausted Error

Memory Exhausted Error is a very common error in WordPress. This article shows you how you can fix this error by increasing the PHP memory limit. Most of the web hosting servers set up a limit on the memory that is being used during the execution of a server-side PHP script. Whenever a script, tries to consume more memory than this limit, the script stops and gives this memory exhaustion error.

Fixing WordPress Memory Exhausted Error

WordPress is written in PHP and therefore, whenever the WordPress scripts try to consume more memory than the defined limit, you will see this error as shown in the following screenshot.

WordPress Memory Exhausted Error

Fatal error: Allowed memory size of XXXXXXX bytes exhausted (tried to allocate XXXXXXX bytes) in /users/xxx/public_html/wp-xxxxx/xxx.php on line xxx

The web-hosting providers, especially the shared web hosting providers have set this limit around 64 MB. Wherever possible, WordPress automatically tries to increase this limit according to its execution of PHP files and their execution environment requirements. But if you are getting this error, then you need to solve it manually.

There are a few levels at which this memory limit can be set. The first and utmost level is the level of your web server. Most of the web hosting services like Hostgator, Bluehost, Siteground, etc. provide cPanel or other GUI control panel using which you can easily increase different PHP environment variables like the memory limit.

Steps To Increase PHP Memory Limit in cPanel

The steps to follow in order to increase your web server’s PHP memory limit are given below.

  1. Log into your cPanel account.
  2. Look for PHP .ini editor option.

PHP .ini Editor

  1. Select either the Basic Mode or Editor Mode. Basic Mode is good for beginners & non-technical users while editor mode is good for technical users.

Choose Mode & Directory

  1. Choose the directory to be affected with these settings and as soon as you’ll select the directory, the PHP settings table will appear automatically.
  2. Now, scroll to the memory_limit option and change the value here in the input box. In our case, I changed the limit to 1024M.

PHP Memory Limit Option

  1. Click on the Apply button given at the end of this settings table to make sure that these settings actually apply on your web server.

Given below is the screenshot for the same settings using the Editor mode.

PHP .ini Editor Mode

Basically, we’re editing the .ini file here. This file stores the configuration for the execution of PHP files on the current web server. You can not just change the memory_limit here but also many other factors like max_execution_time which is the maximum time a PHP script is allowed to execute on the webserver.

Defining PHP Memory Limit in WordPress Configuration File (wp-config.php)

For most of the users, the memory exhausted error will be resolved after following all of the above steps. But if still there, then the PHP memory is being limited at another level, maybe at the WordPress level.

WordPress also has a constant that can be defined in its configuration file, i.e., wp-config.php and this can also limit the PHP memory. First of all, make sure, you have sufficient memory limit set at the webserver level.

Open the wp-config.php file. It is located in the root folder of your WordPress installation directory. You can load it using any FTP client or can use the browser-based GUI file-managers as the one that comes within cPanel.

At the end of this file, where the comments say, That’s all, stop editing! Happy blogging, add the following line of code.

define( 'WP_MEMORY_LIMIT', '1024M' );

By adding this line, you’re basically defining the WordPress Memory Limit Constant for PHP. Before adding this line, make sure that if this constant is already defined in the wp-config.php file and if it is already there, then instead of adding the above line again, simply edit the already existing line to change the memory value to a higher value.

Defining the PHP Memory Limit in .htaccess file

Sometimes your .htaccess file may also trouble in this matter, so you can also define the PHP Memory limit in .htacess file. You’ve to just add the following line to your .htacess file.

php_value memory_limit 256M

Make sure that .htacess file is only located on Apache Web Servers and by default it is hidden. Make sure if you are using FTP software, you have enabled the option to view the hidden files and similarly the web browser-based GUI file managers also have the option to view or hide the hidden files.

I hope that this guide helped you to solve the WordPress Memory Exhausted Error by increasing the PHP Memory limit. If you found this guide useful, do share it with others who might be facing the same trouble and wanted to get rid of it. If you’ve any questions in your mind, feel free to ask us via the comments section below.

Although for most of the users, this error will be fixed using the guidance given in this article but you’re able to solve it using some other way, share that also in the comments section so that we can help more and more people facing this error. Also, don’t forget to subscribe to WTMatter for more such useful articles.

Subscribe To WTMatter!

Receive updates of our latest articles via email. Enter your email address below to get started.

Leave a Reply

Your email address will not be published. Required fields are marked *