WordPress sets a default PHP memory limit during the installation process and there are times when you might need to increase this limit. Instances when this might happen include error diagnosis, and plugin or theme installation. For example, you might be getting the white screen of death or another error which is occurring because of a lack of memory.
In other instances, some themes and plugins may require WordPress to have access to more memory than is currently available. In both situations, you should increase the PHP memory limit.
Depending on your hosting, you may not be able to increase the memory size. Many shared hosts limit the amount of memory used by WordPress and some may not allow you to increase the PHP memory limit. Before you do anything, you should speak to your hosting provider first. If they do allow you to increase the PHP memory limit, they may even do for you. At the very least, they can advise you about the maximum limit allowed in your plan.
What to Set Your PHP Memory Limit to?
If you have a problem with WordPress, you should search the internet to and try to diagnose your issue. Assuming that a lack of memory is causing the problem, you can increase the limit until the issue is resolved.
On the other hand, if you need to increase the memory limit for a plugin or theme, then the developer should be able to tell you the amount of PHP memory required.
Three Ways to increase the PHP memory limit for WordPress
There isn’t only one way to achieve a PHP memory increase with WordPress. There are three options available. You must complete the first option and either one of the second options may or may not work for you. In some instances, option number two will work and in other cases, option number three will work. It may be that neither option actually increases the memory limit and you’ll need to contact your hosting provider.
1. Edit wp-config.php
You will need to complete this step before doing anything else. The wp-config.php file tells WordPress how much memory it’s allowed to use. Even if your server is set to a higher amount, the wp-config.php can still limit the amount used by WordPress. Therefore, before you do anything, you need to increase this limitation.
Open your wp-config.php file which can be found in the root directory of your WordPress installation. Search for a line which says:
In some cases, the limit will be set to different amounts. Simply edit the number before the M (Megabytes) to the desired amount. If your wp-config.php file doesn’t contain this line, you can add it yourself at the end of the file.
2. Edit php.ini
If you have access to the php.ini file on your server, you can edit it to increase the memory allocation. Some hosting providers and plans don’t provide access to the php.ini file. If this is the case, you should skip this part and move on to editing the .htaccess file below.
3. Edit .htaccess
If you don’t already have an .htaccess file, you can create one in notepad by saving an empty file name and using the .htaccess extension. If you already have an .htaccess file, then you can just add the following line to the top:
php_value memory_limit 128M
This line of code will increase your memory limit to 128MB.
Before you do anything, you should check that your hosting provider allows you to increase PHP memory limits. Then the next thing you need to do is edit the wp-config.php file to tell WordPress how much memory it can use.
You then need to ensure that your server can provide that amount of memory by editing the php.ini file. Some hosts don’t always provide access to the php.ini file. Alternatively, if you can’t edit your php.ini file, or it doesn’t seem to have any effect, then you should edit your .htaccess file.
If none of the above has worked, you will need to contact your hosting provider and ask them to help you. It may be that on your current hosting plan, you can’t increase memory allocation. In some cases, the support team has to do it for you.