Tutorial 📅 November 10, 2025 📖 8 min read

How to Increase PHP Memory Limit (WordPress Fix 2025)

Fix 'Allowed memory size exhausted' error in WordPress. 7 proven methods to increase PHP memory limit: php.ini, wp-config.php, .htaccess, cPanel. Step-by-step guide with screenshots.

You're working on your WordPress site, and suddenly you see this terrifying error message:

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 2348617 bytes) in /path/to/wordpress/file.php

Your site might be partially broken, you can't upload images, plugins won't activate, or WordPress updates fail. The culprit? PHP memory limit is too low.

In this comprehensive guide, I'll show you 7 proven methods to increase your PHP memory limit in WordPress - from the easiest (wp-config.php) to advanced server-level configurations. You'll fix this error permanently.

What is PHP Memory Limit?

PHP memory limit is the maximum amount of server memory (RAM) that a single PHP script can use. When a WordPress page loads, it runs PHP code that consumes memory. If it tries to use more memory than allowed, PHP kills the script and shows the "memory exhausted" error.

Why Does WordPress Run Out of Memory?

WordPress Memory Recommendations:
• 128MB: Minimum for basic WordPress sites
• 256MB: Recommended by WordPress for standard sites
• 512MB: WooCommerce, membership sites, or 20+ plugins
• 1024MB (1GB): Large enterprise sites or heavy page builders

Check Your Current PHP Memory Limit

Before making changes, check your current memory limit:

Method 1: WordPress Site Health

  1. Go to WordPress Admin Dashboard
  2. Navigate to Tools → Site Health → Info
  3. Expand the Server section
  4. Look for PHP memory limit

Method 2: Create a phpinfo() Page

<?php phpinfo(); ?>

Save this as info.php in your WordPress root directory, then visit yourdomain.com/info.php. Search for "memory_limit".

Security Warning: Delete the info.php file immediately after checking! It exposes sensitive server information.

Method 3: WordPress Plugin

Install the free WP Server Health Stats plugin to see all PHP settings including memory limit.

Method 1: Increase Memory Limit via wp-config.php (Easiest)

This is the easiest and most common method that works for 80% of WordPress sites.

Step-by-Step Instructions:

  1. Connect to your site via FTP or File Manager (cPanel, SFTP, etc.)
  2. Locate wp-config.php in your WordPress root directory
  3. Download a backup of wp-config.php (important!)
  4. Edit wp-config.php
  5. Find the line that says: /* That's all, stop editing! Happy publishing. */
  6. Add this line BEFORE that comment:
define('WP_MEMORY_LIMIT', '256M');

Complete Example:

define('DB_COLLATE', '');

// Increase WordPress Memory Limit
define('WP_MEMORY_LIMIT', '256M');

/* That's all, stop editing! Happy publishing. */

Increase Admin Memory Limit (Optional):

WordPress admin area can use a separate, higher limit:

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

WP_MAX_MEMORY_LIMIT only applies to admin pages (dashboard, plugin updates, etc.).

Save and Test:

  1. Save wp-config.php
  2. Upload it back to your server (overwrite the old file)
  3. Clear your site cache if using a caching plugin
  4. Go to Tools → Site Health → Info → Server to verify the new limit
Did This Method Work? If you see the new memory limit in Site Health, you're done! If not, your host has a hard limit set in php.ini. Continue to Method 2.

Method 2: Edit php.ini File (VPS/Dedicated Servers)

If wp-config.php didn't work, you need to edit the server-level PHP configuration file.

Find Your php.ini Location:

php --ini

Common locations:

Edit php.ini:

sudo nano /etc/php/8.1/fpm/php.ini

Find the line:

memory_limit = 128M

Change it to:

memory_limit = 256M

Restart PHP Service:

For PHP-FPM:

sudo systemctl restart php8.1-fpm

For Apache:

sudo systemctl restart apache2

For Nginx:

sudo systemctl restart php8.1-fpm
sudo systemctl reload nginx
Shared Hosting Users: You may not have access to the main php.ini file. Check if your host allows a local php.ini in your public_html directory, or use Method 3 (.htaccess) instead.

Method 3: Use .htaccess File (Apache Servers)

If you're on Apache (not Nginx) and don't have php.ini access, try adding directives to .htaccess.

Edit .htaccess:

  1. Locate .htaccess in your WordPress root directory
  2. If it doesn't exist, create it
  3. Add these lines at the top of the file:
php_value memory_limit 256M

Alternative Format (if the above doesn't work):

<IfModule mod_php7.c>
php_value memory_limit 256M
</IfModule>

Save and reload your site.

500 Internal Server Error After Edit? Your server doesn't allow .htaccess PHP directives. Remove those lines immediately and use Method 4 instead.

Method 4: cPanel PHP INI Editor (Shared Hosting)

Most cPanel hosts provide a graphical interface to edit PHP settings without touching files.

Steps:

  1. Log in to cPanel
  2. Find and click "Select PHP Version" or "MultiPHP INI Editor"
  3. Select your domain from the dropdown
  4. Find memory_limit
  5. Change the value to 256M or higher
  6. Click Apply

Some hosts have a maximum limit (e.g., 256M). If you need more, contact support.

Method 5: ini_set() in PHP Code (Last Resort)

You can try setting the memory limit directly in PHP code, though this is the least reliable method.

Add to wp-config.php (after opening PHP tag):

ini_set('memory_limit', '256M');

Or create a custom plugin:

<?php
/**
 * Plugin Name: Increase Memory Limit
 */
ini_set('memory_limit', '256M');
?>

Save as increase-memory.php and upload to wp-content/plugins/, then activate.

Why This Might Not Work: Many hosts disable ini_set() for security reasons. If this method fails, use php.ini or contact your host.

Method 6: Contact Your Hosting Provider

If you're on shared hosting and none of the above methods work, contact support.

What to Say:

"Hi, I'm experiencing 'Fatal error: Allowed memory size exhausted' on my WordPress site. Could you please increase the PHP memory limit to 256MB for my account?"

Most hosts will do this for free within minutes.

Method 7: Upgrade Your Hosting Plan

If your host refuses to increase the limit or charges extra, it might be time to upgrade:

Manage Your WordPress VPS Without the Hassle

Editing PHP configs, restarting services, and troubleshooting memory errors is tedious. VPS Commander provides a simple web interface to manage PHP settings, monitor memory usage, and restart services with one click - no terminal knowledge required.

Try VPS Commander - Starting at $2.99/month

Troubleshooting: Memory Limit Still Not Increasing?

Check Which Method is Active:

Create a phpinfo() page and search for "memory_limit". It will show you:

If they're different, the Master Value wins.

Common Issues:

1. PHP-FPM Not Restarted

After editing php.ini, you MUST restart PHP-FPM:

sudo systemctl restart php8.1-fpm

2. Wrong php.ini File

PHP has multiple ini files (CLI vs FPM vs Apache). Edit the correct one:

php -i | grep "Loaded Configuration File"

3. Editing Wrong php.ini Section

Make sure you're editing under [PHP] section, not [CLI] or other sections.

4. Host Has Hard Limit

Your hosting provider might have a maximum cap (e.g., 256MB on shared plans). Contact support.

5. Nginx Ignoring .htaccess

.htaccess only works on Apache. If you're on Nginx, use php.ini or wp-config.php.

Should You Increase Memory Limit or Optimize WordPress?

Increasing memory limit is a quick fix, but if your site constantly needs 512MB+ for simple pages, you have deeper issues.

Instead of Blindly Increasing Memory:

  1. Audit your plugins: Deactivate plugins one by one to find memory hogs
  2. Use Query Monitor plugin: Identify slow database queries
  3. Optimize images: Use WebP format and lazy loading
  4. Enable caching: WP Super Cache or W3 Total Cache
  5. Upgrade PHP version: PHP 8.1+ is significantly more memory-efficient than 7.x
  6. Use object caching: Redis or Memcached for database query caching
  7. Limit post revisions: Add define('WP_POST_REVISIONS', 3); to wp-config.php
Best Practice: Set memory limit to 256MB, then optimize your site. Only increase further if truly needed. A well-optimized WordPress site rarely needs more than 256MB.

How to Monitor WordPress Memory Usage

1. Query Monitor Plugin

Shows real-time memory usage per page load. Install from WordPress.org.

2. Add to Footer (Quick Debug)

Add to your theme's footer.php (temporarily):

<?php
echo '<!-- Memory Usage: ' . round(memory_get_peak_usage() / 1024 / 1024, 2) . ' MB -->';
?>

View page source and scroll to bottom to see memory usage.

3. Server-Level Monitoring

Use tools like New Relic, Datadog, or built-in VPS monitoring to track PHP-FPM memory consumption.

Security Considerations

Don't Set Memory Limit Too High:
• 512MB+ on shared hosting can get your account flagged for abuse
• Malicious scripts could consume all server RAM
• Use only what you need, monitor usage, optimize first

Safe Limits by Server Type:

Complete Troubleshooting Checklist

  1. ✅ Checked current memory limit (Site Health or phpinfo)
  2. ✅ Added define('WP_MEMORY_LIMIT', '256M'); to wp-config.php
  3. ✅ Cleared site cache
  4. ✅ Verified change in Site Health
  5. ✅ If not working: Edited php.ini and restarted PHP-FPM
  6. ✅ Tried .htaccess method (Apache only)
  7. ✅ Used cPanel PHP INI Editor (if available)
  8. ✅ Contacted hosting support
  9. ✅ Monitored memory usage after increase
  10. ✅ Optimized plugins and queries

Frequently Asked Questions

What does "Fatal error: Allowed memory size exhausted" mean?

Your PHP script tried to use more RAM than the configured memory_limit allows. PHP kills the script to prevent server crashes.

Is 256MB enough for WordPress?

Yes, 256MB is WordPress' official recommendation and works for 90% of sites. WooCommerce or sites with 20+ plugins may need 512MB.

Can I set different memory limits for admin and frontend?

Yes! Use WP_MEMORY_LIMIT for frontend and WP_MAX_MEMORY_LIMIT for admin area.

Will increasing memory limit make my site faster?

No. Memory limit only prevents crashes. Site speed depends on caching, database optimization, and server resources.

Why does my host limit PHP memory?

On shared hosting, limiting memory prevents one site from consuming all server RAM and crashing other sites on the same server.

What's the maximum memory limit I can set?

Depends on your hosting plan. Shared hosts typically cap at 256MB-512MB. VPS/dedicated servers can go higher based on available RAM.

Conclusion: Fix WordPress Memory Errors Permanently

The "Fatal error: Allowed memory size exhausted" error is frustrating but easy to fix. Here's the quick recap:

Quick Fix (Works for Most):

// Add to wp-config.php
define('WP_MEMORY_LIMIT', '256M');

If That Doesn't Work:

  1. Edit php.ini: memory_limit = 256M
  2. Restart PHP-FPM: sudo systemctl restart php8.1-fpm
  3. Or use cPanel PHP INI Editor
  4. Or contact your host

After Fixing:

Remember: Increasing memory is a temporary fix. For long-term stability, optimize your WordPress site, remove bloated plugins, and use caching.

Next Steps:
✅ Increase memory limit using wp-config.php
✅ Install Query Monitor to track usage
✅ Deactivate unnecessary plugins
✅ Enable caching
✅ Monitor your site's performance

Related Articles