Type something to search...
How to increase the PHP memory limit in WordPress?

How to increase the PHP memory limit in WordPress?

To increase the PHP memory limit in WordPress, add define( 'WP_MEMORY_LIMIT', '256M' ); to your wp-config.php file, just above the line that says "That's all, stop editing!" If that doesn't work, your server's own PHP limit is lower than what you requested, so you'll need to raise memory_limit in php.ini, .user.ini, .htaccess, or your hosting control panel, or ask your host to increase it for you.

Running out of memory is one of the most common causes of WordPress errors, especially on sites with page builders, WooCommerce, or lots of plugins. In this guide, you'll learn what the PHP memory limit is, how to check your current limit, every reliable method for increasing it, how WordPress's own memory constants work, and what to do if raising the limit doesn't solve the problem.

What Is the PHP Memory Limit?

WordPress is written in PHP. Every time someone loads a page, PHP starts a process that loads WordPress core, your theme, and your plugins into memory, runs the code, and builds the page. The PHP memory limit is the maximum amount of RAM a single PHP process is allowed to use.

This limit exists to protect the server. Without it, one badly written script could consume all the memory and bring down every site on the server. Hosts set a default value in PHP's configuration, often somewhere between 128 MB and 512 MB, though some budget plans use lower limits.

When a page needs more memory than the limit allows, PHP stops immediately and throws a fatal error.

Signs You Need More PHP Memory

You probably need to increase the memory limit if you see:

  • The "Allowed memory size exhausted" error: A message like Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes). The first number is your limit in bytes. In this example, 134,217,728 bytes is 128 MB.
  • A critical error message: WordPress shows "There has been a critical error on this website" and often sends an email to the admin address with details, which may mention memory.
  • A white screen: Blank pages, particularly in the admin or when using a page builder.
  • Failed uploads or imports: Large image uploads, image resizing, or content imports stopping partway.
  • Page builder or editor problems: Editors that fail to load or show endless spinners.
  • Plugin or theme installation failures: Updates that fail without a clear reason.

How to Check Your Current PHP Memory Limit

Before changing anything, find out what you're working with.

Using Site Health

  1. Go to Tools > Site Health in your WordPress dashboard.
  2. Click the Info tab.
  3. Expand the Server section and look for PHP memory limit. This is the server's limit.
  4. Expand the WordPress Constants section and look for WP_MEMORY_LIMIT and WP_MAX_MEMORY_LIMIT. These are the limits WordPress requests.

Using WP-CLI

If you have SSH access:

# Server's PHP memory limit (CLI may differ from the web server)
wp eval 'echo ini_get( "memory_limit" ) . PHP_EOL;'

# WordPress constants
wp eval 'echo WP_MEMORY_LIMIT . " / " . WP_MAX_MEMORY_LIMIT . PHP_EOL;'

Keep in mind that PHP on the command line often uses a different configuration file from PHP on the web server, so Site Health is the more reliable source for your site's actual web limit.

How WordPress Memory Limits Work

WordPress has two constants that control how much memory it asks for:

  • WP_MEMORY_LIMIT: The memory WordPress requests for front-end requests. The default is 40 MB for single sites and 64 MB for Multisite.
  • WP_MAX_MEMORY_LIMIT: The memory WordPress requests for admin tasks and memory-intensive operations, like image processing and updates. The default is 256 MB.

Here's the important part: WordPress only ever raises the memory limit. If your server's memory_limit is already higher than WP_MEMORY_LIMIT, WordPress uses the server's value. And WordPress can't raise the limit above what the server allows if the host has locked the setting. That's why defining WP_MEMORY_LIMIT sometimes seems to do nothing.

Method 1: Edit wp-config.php

This is the first thing to try, and it works on many hosts.

  • Back up your site: At minimum, download a copy of wp-config.php before editing it.

  • Open wp-config.php: Connect with your host's File Manager, FTP/SFTP, or SSH. The file is in your WordPress root folder, the same folder as wp-admin and wp-content.

  • Add the constants: Find the line /* That's all, stop editing! Happy publishing. */ and add these lines just above it:

define( 'WP_MEMORY_LIMIT', '256M' );
define( 'WP_MAX_MEMORY_LIMIT', '512M' );
  • Save and upload: Save the file, upload it if you edited it locally, and reload your site.

  • Check Site Health: Go back to Tools > Site Health > Info and confirm the new values.

Placement matters. If you add these lines below the "stop editing" line, WordPress will already have loaded its settings and your change won't take effect.

For most sites, 256M for WP_MEMORY_LIMIT is plenty. WooCommerce stores, membership sites, and sites using heavy page builders may benefit from the higher WP_MAX_MEMORY_LIMIT value for admin tasks.

Method 2: Edit php.ini

If wp-config.php doesn't work, your server's PHP limit is probably lower than what you requested. On servers where you can edit PHP's configuration directly, such as a VPS, dedicated server, or some shared hosts, update php.ini.

  • Find the right php.ini file: On a VPS, you can find the loaded configuration file with:
php --ini

For the web server, the path is shown on a phpinfo() page or in your host's control panel. On Ubuntu with PHP-FPM, it's usually something like /etc/php/8.3/fpm/php.ini.

  • Edit the memory limit: Find the memory_limit line and change it:
memory_limit = 256M
  • Restart PHP: Changes to php.ini require restarting PHP-FPM or your web server:
sudo systemctl restart php8.3-fpm

Replace 8.3 with your PHP version. If you use Apache with mod_php, restart Apache instead with sudo systemctl restart apache2.

On some shared hosts, you can create a php.ini file in your WordPress root folder containing just the memory_limit line. Whether this works depends entirely on your host's setup.

Method 3: Create or Edit .user.ini

Many hosts run PHP through PHP-FPM or CGI, where you can't edit the main php.ini but PHP does read a file called .user.ini in your site's folder.

  • Create the file: In your WordPress root folder, create a file named .user.ini if it doesn't already exist.

  • Add the setting:

memory_limit = 256M
  • Wait for it to apply: PHP caches .user.ini settings, by default for 300 seconds (five minutes). Wait a few minutes, then check Site Health.

Because the file starts with a dot, it's hidden by default. In cPanel's File Manager, enable Show Hidden Files (dotfiles) under Settings.

Method 4: Edit .htaccess

On Apache servers running PHP as an Apache module (mod_php), you can set the memory limit in .htaccess. Back up the file first, then add this line near the top, outside the # BEGIN WordPress and # END WordPress markers:

php_value memory_limit 256M

Be careful: if your server runs PHP-FPM or CGI instead of mod_php, which is very common today, this line causes a 500 Internal Server Error. If that happens, remove the line immediately and use .user.ini instead. Nginx servers ignore .htaccess entirely.

Method 5: Use Your Hosting Control Panel

Many hosts let you change PHP settings without editing any files. This is often the easiest and most reliable method.

cPanel

  1. Log in to cPanel.
  2. Open Software > MultiPHP INI Editor (or Select PHP Version, then Options, on hosts using CloudLinux).
  3. Choose your domain from the dropdown.
  4. Find memory_limit and set it to 256M.
  5. Click Apply or Save.

Plesk

  1. Go to Websites & Domains and select your domain.
  2. Open PHP Settings (or PHP in newer versions).
  3. Change memory_limit to 256M.
  4. Click OK or Apply.

Managed WordPress Hosts

Managed hosts often set generous memory limits by default and may not let you change them. Check your host's dashboard or knowledge base, or contact support. Many will raise it on request if your plan allows.

Method 6: Ask Your Host

If none of the above methods work, your host has probably locked the memory limit at the server level. Contact their support team and ask them to increase the PHP memory_limit for your site. Mention the exact error message, which helps them understand what's happening. If your plan's maximum is too low for your site, it may be time to consider a higher plan or a different host.

How Much PHP Memory Does WordPress Need?

There's no single right answer, since it depends on your theme, plugins, and traffic. As a general guide:

  • Simple blogs and brochure sites: 128 MB is usually enough.
  • Sites with page builders or many plugins: 256 MB is a comfortable level.
  • WooCommerce stores, LMS, and membership sites: 256 MB to 512 MB, especially for admin tasks, imports, and reports.
  • Large imports or heavy processing: Temporary higher limits may help, but it's often better to process data in smaller batches.

More isn't always better. The memory limit is per PHP process. If your server has 2 GB of RAM and runs 10 PHP workers at once, setting a 1 GB limit per process could let a few heavy requests use up all available memory. Keep the limit reasonable for your server's resources.

Checking Memory Usage in Your Own Code

If you want to see how much memory a page actually uses, you can log peak memory usage. Add this to a custom plugin or your child theme's functions.php temporarily, with WP_DEBUG_LOG enabled:

function sajjad_log_peak_memory() {
    if ( ! current_user_can( 'manage_options' ) ) {
        return;
    }

    $peak = size_format( memory_get_peak_usage( true ) );
    $uri  = isset( $_SERVER['REQUEST_URI'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';

    error_log( sprintf( 'Peak memory: %s on %s', $peak, $uri ) );
}
add_action( 'shutdown', 'sajjad_log_peak_memory' );

Browse a few pages as an administrator, then check wp-content/debug.log. Remove the snippet when you're done. For deeper analysis, the free Query Monitor plugin shows memory usage, database queries, and PHP errors for each page directly in the admin toolbar.

What If Increasing the Memory Limit Doesn't Help?

Sometimes raising the limit only delays the error, or the error keeps appearing no matter how high you go. That usually means something is using memory it shouldn't.

  1. Find the culprit: The memory exhausted error message includes a file path. If it points to a specific plugin or theme folder, such as wp-content/plugins/some-plugin/, that's your likely cause.

  2. Deactivate plugins one by one: Go to Plugins > Installed Plugins and deactivate plugins one at a time, testing after each. If you can't access the dashboard, rename the wp-content/plugins folder via FTP to deactivate all plugins at once, then rename it back and reactivate them individually.

  3. Switch to a default theme temporarily: Activate a default theme like Twenty Twenty-Five to rule out your theme.

  4. Update everything: Outdated plugins and themes may have memory leaks that have since been fixed. Make sure you're also running a supported PHP version, ideally PHP 8.2 or newer.

  5. Look for infinite loops: Custom code that calls itself repeatedly, such as a save_post hook that calls wp_update_post() without removing itself first, can consume memory endlessly.

  6. Process data in batches: Imports, exports, and bulk operations should handle a limited number of items at a time rather than loading everything into memory at once.

  7. Check the database: Huge autoloaded options in wp_options are loaded into memory on every request. Cleaning them up can reduce memory usage across your entire site.

A memory error caused by a single faulty plugin is usually better solved by replacing or fixing that plugin than by raising the limit higher and higher.


FAQ: Increasing the PHP Memory Limit in WordPress

WordPress requests 40 MB for single sites and 64 MB for Multisite on the front end, and 256 MB for admin tasks. The actual limit also depends on your server's PHP memory_limit setting, which WordPress will not lower.

Your host probably limits PHP memory at the server level, and WordPress can't exceed it. Increase memory_limit through php.ini, .user.ini, your hosting control panel, or ask your host to raise it.

Yes, within reason. Values like 256M or 512M are common and safe on most servers. Very high values can let faulty code use too much of the server's RAM, so keep the limit proportional to your server's resources.

WP_MEMORY_LIMIT applies to front-end requests, while WP_MAX_MEMORY_LIMIT applies to admin tasks and memory-heavy operations like image processing and updates.

Add it above the line that says That's all, stop editing! Happy publishing. Anything placed below that line is loaded too late to take effect.

Your server probably runs PHP-FPM or CGI, which doesn't support php_value directives in .htaccess. Remove the line and use .user.ini or your hosting control panel instead.

WooCommerce recommends a memory limit of at least 256 MB. Larger stores with many products, extensions, or heavy reporting may benefit from more for admin tasks.


Conclusion

Increasing the PHP memory limit in WordPress usually takes just a couple of minutes. Start by adding WP_MEMORY_LIMIT and WP_MAX_MEMORY_LIMIT to wp-config.php above the "stop editing" line. If Site Health shows no change, raise the server's memory_limit through your hosting control panel, .user.ini, php.ini, or .htaccess on mod_php servers, or ask your host to do it for you.

Just remember that more memory isn't a cure for every problem. If a site keeps running out of memory even at generous limits, use Query Monitor, the error message's file path, and some careful plugin testing to find the real cause. A well-tuned memory limit combined with lean, well-coded plugins keeps your WordPress site stable, fast, and free of those frustrating fatal errors.

Tags :
Share :

Related Posts

What are the best WordPress security plugins?

What are the best WordPress security plugins?

The best WordPress security plugins for most sites are Wordfence, Sucuri Security, Solid Security, MalCare, All-In-One Security (AIOS), Patchstack, a

Dive Deeper
What is the difference between posts and pages in WordPress?

What is the difference between posts and pages in WordPress?

The main difference between posts and pages in WordPress is that posts are timely, dated entries that appear in your blog feed, archives, and RSS fee

Dive Deeper
How much does it cost to build a WordPress website?

How much does it cost to build a WordPress website?

Building a WordPress website can cost anywhere from roughly the price of a domain and a year of budget hosting, if you do it yourself with free tools

Dive Deeper