WordPress Memory Limit Error: How to Increase PHP Memory

September 7, 2025
WordPress Memory Limit Error: How to Increase PHP Memory

If you see errors like “Allowed memory size exhausted” or “WordPress memory limit error”, it means your site is using more PHP memory than allocated by default. WordPress sets a baseline, but heavy themes, plugins, or scripts may require more. Here’s how to safely increase the PHP memory limit.

Step 1: Edit wp-config.php

The easiest way is to add a memory definition in your WordPress configuration file. Open wp-config.php (located in the root folder) and insert this line just above /* That's all, stop editing! */:

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

This increases the memory for front-end usage. For admin tasks, you can also set a higher maximum:

define('WP_MAX_MEMORY_LIMIT', '512M');

Step 2: Update php.ini (if you have access)

If wp-config.php changes don’t work, your server settings may override them. Edit your php.ini file and add:

memory_limit = 512M

Save and restart your web server or PHP service if required.

Step 3: Use .htaccess (Apache servers)

On Apache servers, you can increase memory via .htaccess. Add this line:

php_value memory_limit 512M

Note: Some hosts disallow PHP settings in .htaccess. If you get a 500 error, remove the line immediately.

Step 4: Modify .user.ini (for shared hosting)

On many shared hosting environments, you can create or edit a .user.ini file in your site’s root directory:

memory_limit = 512M

Step 5: Contact Your Hosting Provider

If none of the above work, your host may enforce strict limits. Contact support and request a higher PHP memory allocation. Many hosts will increase it for you, especially if you are on a higher-tier plan.

Step 6: Optimize Instead of Just Increasing

Even with more memory, inefficient code can cause issues. To reduce memory usage:

  • Deactivate and remove unused plugins.
  • Switch to a lightweight theme.
  • Use caching plugins to reduce resource load.
  • Optimize database tables and clean revisions/spam.

Summary

  1. Edit wp-config.php and increase WP_MEMORY_LIMIT.
  2. Update php.ini, .htaccess, or .user.ini depending on your host.
  3. Contact your hosting provider if limits are enforced.
  4. Optimize your site to prevent unnecessary memory consumption.

By increasing PHP memory and optimizing your WordPress environment, you can eliminate memory errors and ensure your site runs smoothly.

Avatar

Written by

satoshi

I’ve been building and customizing WordPress themes for over 10 years. In my free time, you’ll probably find me enjoying a good football match.