WP Memory Limit – good explanation

https://fancythemes.com/increase-wordpress-php-memory-limit/

How to Increase WordPress PHP Memory Limit

There are a number of different reasons why you might want to increase the PHP memory limit of your WordPress site, and there are even a number of different ways to do so. The most common reason to do this is to fix errors that occur when your site begins using more memory than it’s capable of using.

These errors include the white screen of death and the 500 internal server error. You may also simply need to increase your PHP memory limit to a number that’s better suited for your growing site.

Whatever the case may be, you need to raise your limit. Let’s go over the various ways you can accomplish this in WordPress. This tutorial is written for beginners, so feel free to skip any sections you feel are too slow.

What to Set Your WordPress Memory Limit and PHP Memory Limit to

This is a tricky question, and it may require you to contact your host. There are a few things we can do before it comes down to that, however, and they are:

  • Determine the max memory limit set in default-constants.php.
  • Trial and error.

Many of these solutions require you to access your site’s files, so I’ll go over how to do that via FTP for those who are still new to the more technical sides of WordPress.

How to Access Your WordPress Site’s Files via FTP

I’ll use FileZilla for this example, but know that there are plenty of other FTP clients out there. Click here to download a version of FileZilla compatible with your operating system.

Download the installer, and run the installer to install FileZilla. Launch it once it’s finished.

FileZilla Settings
FileZilla Settings

Click File in the menu at the top, and select Site Manager. Enter your site name to label your site, and enter these settings:

  • Host – Your domain example.com
  • Port – Leave blank.
  • Protocol – FTP – File Transfer Protocol
  • Encryption – Only use plain FTP (insecure)
  • Logon Type – Normal

Use the username and password you use to log into your host’s site manager as your username and password for your FTP server. If your host uses cPanel, enter the username, and password you use to access cPanel.

Open the Transfer Settings tab, and check the box for Limit Number of Simultaneous Connections. Enter 8 as the Maximum Number of Connections.

Click Connect to access your site’s files through the FTP server.

Finding Your Site’s WordPress Memory Limit

We can see what our WordPress memory limit is currently being set to by viewing the default-constants.php file. This file contains a few lines of code that deal with memory limits in WordPress.

Root Directory public_html
Root Directory public_html

Open your root directory in FileZilla. This is typically called public_html.

Open your site’s wp-includes file, and find your default-constants.php file. Double-click it to download it to your computer.

Open it with a text editor on your system. You should see a few lines of code that relate your site’s memory limit toward the top of this file:

WordPress Memory Limit
WordPress Memory Limit

What this tells us is that the memory limit in WordPress is set to 64MB for multisite installations and 40MB for regular WordPress sites. The WP_MAX_MEMORY_LIMIT setting underneath those lines of code relate to the amount of memory you’re allowed to use on the administrative side of things.

Basically:

  • WP_MEMORY_LIMIT = front end
  • WP_MAX_MEMORY_LIMIT = back end

This is how we’ll change our site’s WordPress memory limit in the wp-config.php file. We’ll use the define function from the default-constants.php file in the wp-config.php file to override the limit set in the default-constants.php file.

Determining What to Set Your Site’s PHP Memory Limit to

This is where things get a little tricky. How much memory you need depends on a few different factors, mainly the number of plugins you use and how much media exists (and will exist) on your site.

Generally, though, you should choose a number larger than what you found in the default-constants.php file, but it ultimately depends on which file you choose to edit, as you’ll see below.

This is also where we get into the “setting PHP memory limit through trial and error” thing. If you are trying to correct an error by increasing your site’s memory limit, you may need to try a base number first, test your site, and raise the number if your first test does not the correct the issue.

Be sure not to raise this number too high as it could crash your server. It’s unlikely, but it’s better to be safe than sorry. It’s difficult to give a particular maximum number, but you shouldn’t increase the number to anything that’s much higher than you need.

Basically, start at a number that’s higher than the default you found in the default-constants.php file (if you’re editing the wp-config.php file), and increase the number from there as you need.

It’s not recommended, but you can create a file called phpinfo.php. Add this code to it, and upload it to your root directory:

<?php phpinfo(); ?>

The information collected in this file will include what your PHP memory limit is currently set at. However, this is not recommended for novice users as having this file on your site leaves you vulnerable to hackers.

Let’s get into it.

Increasing Your PHP Memory Limit and WordPress Memory Limit

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.

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. It likely won’t be, but double-click it if it is 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 this code to your text editor:

memory_limit 512M

Save the file, and name it php.ini, like so:

Increase PHP Memory Limit in php.ini
Increase PHP Memory Limit in php.ini

If you’re new to FileZilla and FTP clients in general, you’ll notice there are four “views” or “panels” in FileZilla. Take a look at the bottom two, which are side by side. Use the one on the left to find the location on your computer where you saved the php.ini file.

Make sure your wp-admin folder is still open in the right panel. Once you’re certain it is, drag the php.ini file from the left panel over to the right panel to upload the file to your site. Overwrite the original one if you were editing an existing php.ini file.

Refresh FileZilla
Refresh FileZilla

Refresh the FTP client, as depicted in the image above. 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.

Remove the php.ini file from your site if you choose to use another solution.

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 some FTP clients. If you don’t see yours, click Server in FileZilla, and select Force Showing Hidden Files:

Force Showing Hidden Files
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.

Remove the code from the file and re-upload it to your site if you choose to try another solution.

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.

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.

Check out Nick’s comparison of the 5 best hosting providers for WordPress. This post also contains great information on the different types of hosting available for WordPress sites.

Scroll to Top