How to Increase PHP Memory Limit in WordPress

Increase PHP Memory Limit in WordPress

Did you come across PHP memory size exhausted error on your website and want to learn different ways to increase PHP memory Limit? Then you are in the right place.

Memory limit exhausted is one of the most common fatal errors and it can be easily fixed by increasing the PHP memory limit on your site.

There are so many different reasons for why we want to increase the PHP memory limit of the website and also there are many different ways to do so. The most common errors that occur when your site begins to experience a shortage in PHP memory and use more memory than allocated.

These errors include the 500 internal server error, Fatal error: Allowed memory size and white screen of death. To fix these types of errors you need to increase the PHP memory limit that suits better for your website.

In this guide, we will explain how to fix site memory exhausted error by increasing the PHP memory limit.

What is PHP Memory Limit?

Majority of websites are created by PHP, which is a server-side programming language. Every website needs a hosting server to store source code and function properly.

Web servers are similar to any other computer which need memory to efficiently run multiple applications at the same time. Web servers will allocate specific PHP memory limit to serve user request.

When your website requires more memory than the default allocated PHP memory limit, you get to see this error.

Internal Server Error in WordPress

Too many 500 internal server errors will negatively influence the ranking of the site on search results.

3 Ways to Increase PHP Memory Limit in WordPress

WordPress website automatically increases PHP memory limit if it is less than 64MB. If the site has a complex structure and multiple applications than 64MB are often not good enough.

Whatever the case, to make a website work efficiently and respond quickly to users we need to increase WordPress PHP memory limit.

Here are the 3 effective solutions to increase PHP Memory Limit and get rid of 500 internal server errors:

1. Increase WordPress Memory Limit via wp-config.php

First, in your WordPress site open the wp-config.php file which will be located in the root folder. You need to make use of File manager in your hosting control panel or FTP client to access the wp-config.php file.

Next, find the following line at the end of the wp-config.php file which says “That’s all, stop editing! Happy blogging” and paste this code just above that line.

Increase WordPress Memory Limit via wp-config.php

This code tells the web server to increase the WordPress PHP memory limit to 512MB.

Once you are done adding the given code save the changes and upload the wp-config.php file back to the hosting server. You can now refresh your site and the fatal error will disappear.

2. Increase PHP Memory Limit in the php.ini file

If you are using hosting file manager, then go to the Files section in cPanel and click on the File Manager button. Make sure to check the Show Hidden Files checkbox and then click on the Go button.

Open the wp-admin folder and open the file named php.ini or php5.ini. If you couldn’t find it, then create a new file by clicking the New File option in the top left-hand corner. Name the new file as php.ini and click on the create file option in the pop-up.

Once the file is open, edit the following line of code that contains memory_limit and change the M value.  If a new file is created, add this code in the text editor.

Increase PHP Memory Limit in the php.ini file

The M means megabytes, make sure that the value of upload_max_filesize and post_max_size should be the smallest while memory_limit should be the largest.

Save and upload the php.ini or php5.ini file in the wp-admin folder and see if the WordPress internal server error is gone.

3. Increase WordPress Memory Limit via .htaccess

If the above-mentioned strategies don’t do the trick, you can also increase PHP memory limit in WordPress by editing .htaccess file and the file will be located in the root directory.

In some FTP clients, the .htaccess file will be hidden. To edit the file click on Server menu in the FTP client and select Force Showing Hidden Files option.

Add the following line of code which is mentioned below, or edit the line if it already exists in the .htaccess file:

Increase WordPress PHP Memory Limit via .htaccess

Refresh the FTP client and clear the cache for your browser to check if the memory limit error goes away. Try increasing the M value if the error still exists.

Note: If these solutions do not clear the internal server errors, then your web hosting service provider is not allowing you to increase WordPress PHP memory limit in WordPress. Contact your web hosting provider to instruct them to increase WordPress PHP memory limit manually from their side.

That’s all we got in this guide which might help you to solve memory exhausted error in WordPress by increasing the PHP memory limit.

Do let me know thoughts in the comments below.

Leave a Reply