How to Increase PHP Memory Limit in WordPress?

How to Increase PHP Memory Limit in WordPress?

Do you want to change the default php memory limit in the wordpress? So in this article we will tell you the different way to increse php memory limit in the wordpress.

What is the PHP memory limit?

As we know, WordPress relies on PHP and it is a server-side scripting language. Moreover, every website in the WordPress managed by hosting server. But these server has some PHP memory limit to work for all WordPress function properly.

Why the PHP memory limit error occurs?

Sometimes when you are updating a new plugin, but you have already lots of plugins installed on your WordPress site. Then the hosting server gives an error Allowed memory size of site exceeded occurs on screen.

The one of another reason for PHP memory limit is when a WordPress code needs more memory to execute. So you get an error as shown below:

Fatal error: Allowed memory size of 136286400 bytes exhausted 
(tried to allocate 5775295 bytes)

How to check the PHP memory limit in the WordPress?

The WordPress PHP memory limit set by the server can be viewed by the default constant.phpfile in the file manager.

1. So, Firstly open the cPanel and select file manager.

2. Next, open the public_html folder in the WordPress directory.

3. Under wp-includes file, find your default-constant.php file.

4. Download the file and open it in your text editor.

5. Now see the code the max memory limit set for multisite by the web server is 64MB and for the WordPress, it is 40MB.

How To Check PHP Memory Limit

6. Furthermore, in the next line WP_MAX_MEMOERY_LIMIT is set at 256 MB for the use of the administrative function.

Now finally change your PHP memory limit according to the above set value.

The different ways to exceed the PHP memory limit

1. Change the PHP memory limit via the .htacces file.

2. Modify the PHP memory limit in the php.ini file.

3. By increasing the memory limit in the wp-config.php file.

Method 1) Change the PHP memory limit via the .htacces file.

Increase the PHP memory limit by the .htaccess file.
1. For this, download the .htaccess file from the cPanel.

Download .htaccess File

2. Search the line # END WordPress in the file and add the code after it.

php_value memory_limit 256M

Method 2) Modify the PHP memory limit in the php.ini file.

Mostly the hosting server does not allow to edit ‘php.ini’ file.
Besides that, if your host gives permission then edit the file in the text editor and add the code in the file.

memory_limit 256M

Lastly, save the changes and upload the file into the root directory.

Method 3) By increasing the memory limit in the wp-config.php file

Moreover, if any kind of reason the above methods not convenient for your requirements. Then, edit the wp-config.php file in the text editor.

define('WP_MEMORY_LIMIT', '256M')

Finally, go to your website and check the error is solved.

That’s all I hope this article will help to know that how to Increase PHP Memory Limit in WordPress.