How to fix the "Memory Exhausted" Error in WordPress


We will see how to fix this error in 3 minutes (2 if you have your FTP client configured correctly).

This error happens sooner or later to everyone, the message crashes, sometimes it happens only in the Backoffice, other times when installing a theme … it will be something like this:

Fatal error: Allowed memory size of UnNumberVery Large bytes exhausted (tried to allocate UnPuñaoGrandde bytes) in /LaRutaEnTuSerSer/public_html/wp-includes/plugin.php on line XXX

Sure, being a fatal mistake, WordPress can no longer work. To the point, we fix it and then explain why.

How to fix «Allowed memory size of XXX bytes exhausted»

Very easy, in the folder where your WordPress is you go to wp-config.php and add the following line.

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

It should work, if it does not work, you have the memory limit on your php.ini or htaccess, let's see what to do in these cases.

Change "memory limit" in .htaccess

The .htaccess is a hidden file found in the WordPress root, look it up.

The route would be /TuRuta/CarpetaWordpress/.htaccess

Here you have to add the following line:

php_value memory_limit 64M

Change the "memory limit" in the php.ini

As you will know – and if not, I tell you – the php.ini file is the one that stores the main options of your php server, depending on your server it will be on one route or another, the most common is that it is on the route / etc / php5 / apache2 if your machine is Linux, if it isn't there, keep looking, other typical options are /etc/php/7.0/apache2 or / etc / php / apache2

  1. Open it with your favorite text editor, normally you will do it from the console, for example (I like nano):
    sudo nano /etc/php5/apache2/php.ini
    
  2. Find the variable "memory_limit" and change the value to 256M looks like this. Here we would change 64M to 156M
    memory_limit = 64M; Maximum amount of memory a script may consume (64MB)
  3. We restart Apache
    sude service apache2 restart

What if none of this works?

Ok, you've tried all three options and it doesn't work, are you using shared hosting? In this case you will not have been able to access the php.ini and surely that is the problem, if this is your case, we can still try one thing: Create a php.ini for our directory, in some cases it will work, but in most cases it will not.

  1. Go to the root directory of your WordPress
  2. Create a file called php.ini
  3. As in the previous option, add this line (this time there will be nothing else).
    memory_limit = 64M; Maximum amount of memory a script may consume (64MB)

With this we have tried to overwrite a configuration value of our php only for this directory.

If still the ad Allowed memory size of UnNumberVery large bytes exhausted persists, contact technical support to see if they can do something, but most likely you will have to change hosting plans.

Error Explanation

The servers limit the maximum memory that a process can occupy, WordPress for its part always tries to increase this limit to 64 MB, with this it should be sufficient for most cases, but sometimes we exceed in some specific processes, to me, for example, it just happened to me in this online store when installing a lead capture plugin, that's why I wrote this 😀

Being a limit that the server sets, when a process exceeds the memory limit it returns a fatal mistake and the process kills you, it happens a lot when you try to process large files, such as images or databases, in those cases the option to define the limit in the PHP code itself, if you are outside the WordPress environment you should use the following line:

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

I hope you have been useful.

Leave a comment

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