How to Increase Memory Limit on a WordPress Website

By | December 18, 2023

The PHP Memory Limit available on your server can influence the speed and performance of your website. It also helps the server stay optimized and serve individual web pages using a defined memory limit.

Let’s assume the CPU memory or RAM offered on your hosting plan is 500MB. If you have multiple websites on the hosting server, they all share 500MB of memory. The PHP Memory Limit helps you distribute the memory evenly across each website. The memory used by each website at a go is proportional to the traffic it receives.

What now happens when a website wants to serve webpages using a higher value of memory beyond the configured value or if the total available memory on the server is exhausted? The server throws up a WordPress critical error warning or a server-side error after struggling to load slowly over some time. Otherwise, the server would end up serving partial content on the webpage to the visitor.

As you increase the plugins, add-ons and functionality of your WordPress-powered website, you are also expected to increase the memory limit as well. This is because the more the complexity of your website, the more memory would be required to serve its web pages.

Coming to how you can redefine the memory limit on your WordPress-powered website, there are four ways to go about it.

METHOD 1: EDITING THE WP-CONFIG.PHP FILE

The wp-config.php file is usually in the root folder of your website’s WordPress installation. It comes with every installation of WordPress and contains blocks of codes and commands that serve as configuration for the website.

Locate the root directory of the installation and find the wp-config.php file. It is usually below the wp-cong-sample.php file in the directory.

Once you find the wp-config.php file, right-click on it to edit and search the content for the code below:

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

Modify the second parameter to a higher value. From 32, you can change it to 64 or 128. Also, the M stands for Megabytes and you can replace it with G if you intend to modify it to Gigabytes. You may as well not find the code above – that’s not the end of your website. What you simply need to do is add the code and modify it to a higher value.

Save the file and refresh your website to confirm if the changes have been effected.

METHOD 2: MODIFYING THE PHP.INI FILE

The php.ini file is usually generated by the server in the root directory of most website setups and provides instructions to the server on resource management and usage. It can also be manually created if a server supports it.

While most servers support the php.ini file, some do not – even if it is manually created. If this happens, you may need to check your CPanel or DirectAdmin hosting dashboard for other server-side alternatives. Some known alternatives include the MULTI-PHP INI EDITOR, MULTI-PHP MANAGER and PHP SETTINGS.

If you would be editing from the PHP settings or any other in-app server management, you would only be required to enter a higher value for your memory limit. There are no technicalities involved but ensure you select the correct website or domain where you want the settings configured.

However, if you find a php.ini file in your website’s root folder, right-click to edit it and look for the code below across the lines.

memory_limit = 32M

Increase the value to 64, 128 or even 256 depending on the available resources and expectations and your website should run just fine. If you want the value measured in gigabytes, change the M to G as well.

METHOD 3: ADDING A RULE TO THE .HTACCESS FILE

The .htaccess file is a crucial file that contains a set of rules that govern the website serving a visitor. it is located in the root folder of most sites whose hosting server is based on Apache. Nginx-based hosting servers do not use .htaccess files hence, this method only applies to websites hosted on Apache-based servers.

This method is least recommended because some operations on WordPress such as saving permalinks and activating a new theme regenerates the .htaccess files. Hence, the rule added is lost and needs to be added each time the file is regenerated.

If you feel comfortable proceeding with this method, locate the .htaccess file in your website’s root directory. If you cannot find the file, hit settings on the top right-hand corner of your screen, select the show hidden files in the preferences and save.

Once opened, enter the rule below to the .htaccess file.

php_value memory_limit 256M

You can replace 256 with a higher value of your choosing. Do not forget to save the file for the rule to be effective on your website.

STILL EXPERIENCING ISSUES?

If you are still experiencing low memory issues after trying one of the three methods above, you may want to keep increasing to see if that resolves it. If you are having issues with critical errors on WordPress, you may want to see my fix on how you can get that resolved.

Also, avoid using the three methods above on a website as it can result in conflict and confusion leading to server-based error. You may also want to consider reducing the site load or upgrading your hosting plan to accommodate more resources.

You can engage through the comment section if you are unable to resolve the issue on your own and I’ll do well to put you through.

See you in my next article.

Leave a Reply

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