How to Increase WordPress Memory Limit

Increasing the memory limit for WordPress can help resolve issues with running out of memory during tasks like installing plugins or themes, uploading large media files, or migrating content. If you get errors mentioning “exhausted memory” or “allowed memory size”, adjusting the memory limit is often the solution.

Why Increase the Memory Limit

  • WordPress and its plugins need sufficient memory to function properly. The default limit of 128MB can be too low for many sites.
  • Uploading large images, audio, or video files may require more memory.
  • Importing a lot of content from another site or plugin can use extensive memory.
  • Some plugins recommend increasing the memory limit to work properly.

How WordPress Uses Memory

When a page loads in WordPress, PHP allocates a certain amount of memory for WordPress and its plugins to use. This allocation is called the memory limit. Common operations like loading plugins, rendering posts, running database queries, and processing uploaded files require memory.

If the operations going on require more than the allocated memory, you’ll get errors like:

  • “Allowed memory size exhausted”
  • “Out of memory”
  • “Fatal error: Allowed memory size of X bytes exhausted”

Increasing the limit prevents these errors by giving WordPress more memory to work with.

Check Current Memory Limit

Before adjusting the memory limit, check what your current limit is set at.

Create a simple PHP file with this code:

<?php 
echo 'Current memory limit: ' . ini_get('memory_limit') . "\n";
?>

The output will show your current limit, like:

Current memory limit: 128M

128M is 128 megabytes and is WordPress’ default limit.

Increase Memory Limit in wp-config.php

The best way to increase the memory limit for WordPress is to edit wp-config.php and add this line:

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

This will explicitly set the memory limit to 256 megabytes.

Some key points:

  • This must go before the line /* That's all, stop editing! Happy publishing. */
  • Use a value like 256M for 256MB, or 512M for 512MB, etc.
  • Save changes and upload edited file to replace old wp-config.php

By adding this constant, you override the memory limit globally for WordPress operations.

Increase PHP Memory Limit in php.ini

If you don’t have access to wp-config.php, update the PHP memory limit directly by editing php.ini:

memory_limit = 256M

The php.ini file may be located at:

  • /etc/php/7.4/apache2/php.ini
  • /etc/php/8.1/fpm/php.ini
  • /usr/local/etc/php/7.4/php.ini

Restart the web server after changing php.ini.

This will increase the memory for all PHP applications, not just WordPress.

Increase Limit with .htaccess

To change the memory limit for a single WordPress site without affecting other applications, use .htaccess:

php_value memory_limit 256M

This sets 256MB limit only for that specific WordPress installation.

Troubleshooting Issues

  • Web server needs restarting – For changes to php.ini or .htaccess to work, restart Apache/Nginx.
  • Other users override limit – Hosting providers may set hard limits that override your settings. Check with them.
  • Insufficient total memory – If your server has less memory available than the limit you set, it will still crash.
  • Plugins require more memory – Even at higher limits, some plugins may need more memory to import lots of data.

Start conservative with a limit between 256-512MB. Increase gradually as needed while monitoring memory usage.

When to Increase the Limit

Common reasons to bump up the memory limit:

  • Importing lots of posts/pages from an export file
  • Uploading multiple high-resolution images
  • Installing a plugin with large files or that moves lots of data
  • Receiving “exhausted memory” errors in logs or on screen

If none of the above apply, the default 128MB limit may be sufficient. Monitor your site’s memory usage over time.

Conclusion

Adjusting WordPress’ memory limit prevents issues with running out of memory during resource-intensive operations. The best option is defining a custom limit in wp-config.php.

Start with 256-512MB and tweak up or down as needed. Also check for and address any memory-hogging plugins. With an appropriate limit set, you’ll avoid those pesky “out of memory” errors for good!