How to increase the PHP memory limit for WordPress

How to increase the PHP memory limit for WordPress

With a near endless number of configurations that a user can try with WordPress, eventually you will find that your memory limit with PHP just isn’t enough. Everything from plugins such as Elementor not loading to getting 500 internal server errors can bring on headaches. Especially if you have a growing site that’s needs are incrementally increasing.

Whatever the reason you find yourself needing to increase your PHP memory limit, we have a few different ways that will get your website back up and functioning. We have included an index to the left in case you want to just jump to the section that more fits your needs.

WordPress Memory Limits & PHP Memory Limits

Luckily when adjusting your memory limit for your WordPress site you can use a bit of trial and error to get the results you’re looking for. If the memory limit is set too low the website will give an error stating something along the lines there just isn’t enough memory. All you would need to do is just readjust the setting to what is was before, save it, and verify the site is back to normal.

Remember:

  • Only try one of these solutions at a time. If you cannot make one work, make sure you delete the codes from your files before moving onto the next solution.
  • Go back to your site’s root directory (public_html). If you see folders called wp-content, wp-admin and wp-includes, you’re in the right place.
  • Before you get started, clear your browser’s cookies and cache to ensure neither of those are affecting the way your site is appearing in your browser.

Adjust the WordPress Memory Limit

Assuming your PHP settings were already previously adjusted by your hosting provider you can edit the default-constants.php file.

Note: If you are unsure if the php memory limit was set to other than the default settings, contact your hosting provider for more information.

You will find this in the wp-includes folder where you can either download to the PC, edit through cPanel, or even use a command console to either vi or nano into the file.

Inside the file you will be looking for the following code:

//set memory limits
If( !defined(‘WP_MEMORY_LIMIT’) ) {
  If ( is_multisite() ){
       Define(‘WP_MEMORY_LIMIT’, ‘64M’;
   } else {
       Define( ‘WP_MEMORY_LIMIT’, 40M’;
   }
}

What the above code does in WordPress is set the Memory Limit for multisite installations (64M) and single site installations (40M) respectively. The ‘40M’ is what you are going to want to change.Usually plugins like Elementor suggest to have least 128MB available for the software to perform properly. So, for the sake of this article, we will change the ‘40M’ to ‘128M’.

Note: Keep in mind changing the 40M to 128M is not always necessary and you can change this to a lower amount if 128 is too high for your current setup.

Finally reload the file if you downloaded or save if you are editing it directly from your server.

Increasing Your PHP Memory Limit in php.ini

Open your wp-admin folder, and see if a file called php.ini or php5.ini is there. If you do see either file here, download the file to your computer, and open it. (Open a text editor on your computer if the file isn’t there.)

If you are editing your php.ini or php5.ini file, find the line that contains memory_limit and an M value, and change it to this:

memory_limit 512M

If you are creating your own file, add the above code to your text editor to achieve the same results.

Afterwards just save the file. Name it php.ini or php5.ini (if the other name does not give the desired result) if you are creating the file new.

Upload the php.ini or php5.ini file to the server. If you are increasing your memory limit to correct a specific error on your site, refresh your site to see if the error goes away. If it does not, try increasing the 512M value to something else. Alternatively, you can try renaming the php.ini file to php5.ini.

Increasing Your PHP Memory Limit in .htaccess

You can also increase your PHP memory limit with your .htaccess file. This file is located in your root directory. It’s a “dotfile,” which are typically hidden by default in cPanel and in FTP programs like Filezilla.

  • cPanel’s File Manager has a settings button at the top right of the screen. Clicking on this brings up a Preferences Menu with the option “Show Hidden Files (dotfiles)”. Selecting this option reveals the hidden .htaccess file.
  • If your using an FTP program such as Filezilla, just click Server in FileZilla, and select Force Showing Hidden Files.

Double-click the file to download it to your computer, and open it. Add this bit of code to it, or edit the line that’s already there if you find it:

php_value memory_limit 512M

Save the file, and upload it to your root directory, overwriting the original file. Refresh the FTP client, and refresh your site to see if the error you were trying to correct goes away. Try increasing the value if it does not.

Increasing Your WordPress Memory Limit in wp-config.php

Double-click your wp-config.php file to download it to your system. Open it in a text editor, and add this bit of code to it:

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

Save the file, and re-upload it to your root directory, overwriting the original. Refresh the FTP client, and refresh your site to see if the error goes away. Increase the value of 64M as necessary.

If you are getting errors while working in the admin area of WordPress, try adding the WP_MAX_MEMORY_LIMIT code beneath the memory limit code, like so:

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

Increase the max memory limit as necessary. Just make sure it’s always higher than the WordPress memory limit.

Contacting Your Host – Your Last Resort

Many hosts limit the amount of memory your server is allowed to use, especially shared hosts. In fact, many shared hosting providers don’t even give you access to your php.ini file, so if you’re having trouble fixing an error using that method, your host’s limitations may be to blame. If you’re a Cherry Host customer, Contact US, so we can take care of this for you.

All in all, if you have no success by trying to increase your PHP memory limit or WordPress memory limit yourself, you may need to have your site change your limit for you. Your last last resort is to upgrade your entire hosting package. It might be a good idea to do so, anyway, especially if you’ve been on a shared hosting server for a while.

Share this post

Share on facebook
Share on twitter

Business Address

10221 Buena Vista Ave
Suite A
Santee, CA 92071

Customer Service Hours

Monday – Friday: 9:00AM – 5:00PM
Saturday & Sunday: 11:00AM – 3:00PM

Eastern Standard Time

Cherry Host Portal

Return to Customer Portal