How To Increase Php Memory Limit In WordPress?

Posted on the 01 August 2023 by Jitendra Vaswani @JitendraBlogger

If you are WordPress user and seeing a PHP memory limit error message on your dashboard while downloading any new plugin, upgrading your WordPress version or performing other tasks, then a solution to your problem is given below in the guide.

The message may look something like,

“Fatal Error: Allowed memory size of *** bytes exhausted(tried to allocate **** bytes) in /home4/xxx/public_html/wp-includes/plugin.php on line xxx”

WordPress is usually the best platform to run websites and blogs. It provides all the necessary resources to run the website smoothly. But in some exceptional cases, you may encounter this error. You can easily create a website and these kinds of errors are not a big deal.

We usually get up a sufficient amount of memory from WordPress to install a number of plugins without any problem. But when we install large-sized plugins and files to an extent, that it reaches the maximum memory limit offered by WordPress, then such a situation occurs.

Now the question arises of how to resolve such errors.

Well, don’t panic! There are a number of ways to PHP set a memory limit and resolve this problem.

I’ll try to cover a few of them here. The problem might seem big, but the solution is very easy. Yes, it would hardly take you two minutes if you have been on your hosting account before.

But if you have never logged into your hosting account and have never tried your hands on your cPanel, it might seem a little tricky to you! Well, whatever it is, we will only get to know once we will move to the guide, so are you ready??

How To Increase PHP Memory Limit in WordPress?

Before getting on to our guide, let me inform you that it involves a bit of coding skills. If you have got that, then the guide might help you.

But in case, if you are a complete novice, then beware, things might get messy to you. In that case, the best solution for you is to contact your hosting provider and talk to them about the error.

Since you have paid them, it’s your right to get things done right. But, if you know a little bit of coding, then I will suggest reading the guide below and resolving the issue, it will take less time than contacting the customer executive and getting things done.

So let’s get started with the methods.

#Method 1. Increase Memory limit via wp-config.php

This is the best yet easiest way to resolve memory limit errors. In this method, you just need to go to the wp-config.php file on your server and add a line of code there.

Here’s how to do that,

  • Login to your hosting account.
  • On your cPanel, scroll all the way down to Files.
  • Now under files, click on File Manager. You’ll be prompted with the following window.
  • Now select Web Root(public_html/www) and Show Hidden Files. Now select the domain which is having the error(In case there are multiple domains hosted on your hosting), and then click Go.
  • Now on the left side, you’ll see a long list of files in the public_html directory. There, you need to search for the file wp-config.php.
  • Once found, select the file by clicking on it and click on the code editor at the top of the screen. If you can’t find the option, a screenshot for the same is given below.

  • In wp-config.php editor file, just add the following command,

define(‘WP_MEMORY_LIMIT’, ’64M’); 

That’s it! Once you do this, the memory limit on your WordPress would be increased and you no longer have to bear this error.

#Method 2. Increase Memory limit via PHP.ini file

The second method is similar to the above method. But this time, we need to tweak the php.ini file. You can increase the memory limit of your WordPress by adding the command memory_limit = 64M into the php.ini file.

But there is a problem. Not all the hosting providers allow you to access php.ini file. Some hosting providers might allow you to create a duplicate file of  php.ini and the same named file will overwrite the previous file. This way you can edit that file.

But some hosting providers don’t even allow to create the duplicate file. In that case, other methods need to be followed. So, if you don’t get php.ini files on your WordPress, go for other methods.

#Method 3. Increase Memory limit via .htaccess file

The third way to increase the memory limit is by .haccess. If you have a newly created hosting and WordPress account, probably you won’t have this file on your server.

In order to add the command to exceed the limit of your WordPress memory, you’ll have to create this file. Once done, just add the following command line into .htaccess file,

php_value memory_limit 64M  

This command will maximize the memory limit to 64MB. If you want even more memory, just replace the number 64 to 96M, 128M etc and your memory error would be resolved.

For those, who don’t know how to create a file on the hosting account, just follow the below steps

  • Open the directory, where you want to create the file.
  • Click on the New File option on the top left in the corner.
  • Write the name of the file and click on the Create New file button, the file would be created.

#Method 4. Increasing Memory limit via install.php

Now coming to the last method i.e increasing the memory via install.php file. For this, find the wp-admin folder on your server. There, you’ll see a file called install.php.

You need to open this file in the code editor and add the following command line. Once done properly, it will cause the memory increase in WordPress and the issue would be resolved. The command is,

ini_set('memory_limit','32M');

That’s it for the guide! With this, I’ll have to wrap up the article. If you own a website then you must be aware of DDoS attacks. Here is how to protect a website from DDoS attacks.

Also Read:

Conclusion

Now use any of the methods mentioned above and get the PHP memory limit error resolved. It’s that easy!

I hope the guide helped you to get things done. And in case, if you still can’t solve the issue and the problem persists, please contact your hosting provider via live chat or contact form!

And don’t forget to tell us how did you like the guide and which method you found easy? And if you know any other better way, mention it in the comments section below.