wp knowledge mascot PHP memory

How to Increase the PHP Memory in the .wp-config File

Last Updated on April 20, 2022 by WP Knowledge Hub

PHP Memory in WordPress

With more media-rich and interactive elements on your site, the WordPress site’s default PHP memory limit can be exceeded.

WordPress has a PHP memory limit of 32MB by default. If your site has few pages and a limited amount of multimedia content and plugins, that’s fine, but as you add more to your site, the closer you get to the maximum.

WordPress will automatically increase available memory to 40MB when this limit is reached, such as when uploading a video or interactive web element.

Why am I getting a PHP memory error?

You can increase the PHP memory available to WordPress beyond 40MB, but it is worth looking into the cause of memory max-outs before increasing your limit. Because adding more memory is only a temporary fix if the root cause of your memory issue isn’t simply available space, but something tied to other elements of your site. The problem will continue to persist, and you’ll keep getting the same error.

Here are some common causes of the PHP memory being maxed-out:

  1. Too many Plugins
  2. An Outdated PHP Version
  3. Large Media Files Like Videos

If you still can’t figure out what the issue is, you might need to increase the PHP limit through the .wp-config file. This is one of WordPress’ core files located in the root directory.

How to Increase the PHP Memory Limit in WordPress

The easiest way is to do it through the .wp-config file:

Option 1. Edit your wp-config.php file.

First, log in to your hosting panel (like cPanel or Plesk) or use FTP (FileZilla or Cyberduck, for instance).

Open the wp-config.php file in the root directory.

Just above the line that says: /* That’s all, stop editing! Happy publishing. */, paste this code:

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

256M is just a placeholder value that should be good to go for almost every scenario, but if you need more, you can try changing 256M to 512M.

Option 2: Edit your .htaccess file (Option 1 is still the best and most successful method!).

Using the same method as Option 1, access your root directory with your hosting panel’s File Manager, or use an FTP client like FileZilla and find the .htaccess file.

Once you’ve accessed the file, add this code after #END WordPress:

    php_value upload_max_filesize 50M
    php_value post_max_size 70M
    php_value memory_limit 256M
    php_value max_execution_time 300
    php_value max_input_time 300

Option 3. Contact Your Hosting Provider