You're working on your WordPress site, and suddenly you see this terrifying error message:
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?
- Too many plugins: Each plugin consumes memory, especially poorly-coded ones
- Large images: Uploading or processing high-resolution images
- WordPress updates: Core/plugin updates need extra memory
- WooCommerce: Product imports and heavy database queries
- Page builders: Elementor, Divi, and similar tools are memory-intensive
- Low default limits: Many shared hosts set 32MB-64MB limits (way too low)
• 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
- Go to WordPress Admin Dashboard
- Navigate to Tools → Site Health → Info
- Expand the Server section
- 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".
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:
- Connect to your site via FTP or File Manager (cPanel, SFTP, etc.)
- Locate wp-config.php in your WordPress root directory
- Download a backup of wp-config.php (important!)
- Edit wp-config.php
- Find the line that says:
/* That's all, stop editing! Happy publishing. */ - 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:
- Save wp-config.php
- Upload it back to your server (overwrite the old file)
- Clear your site cache if using a caching plugin
- Go to Tools → Site Health → Info → Server to verify the new limit
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:
/etc/php/8.1/fpm/php.ini(Ubuntu/Debian with PHP-FPM)/etc/php.ini(CentOS/RHEL)/usr/local/lib/php.ini(Some custom setups)~/public_html/php.ini(Shared hosting - user-level)
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
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:
- Locate
.htaccessin your WordPress root directory - If it doesn't exist, create it
- 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.
Method 4: cPanel PHP INI Editor (Shared Hosting)
Most cPanel hosts provide a graphical interface to edit PHP settings without touching files.
Steps:
- Log in to cPanel
- Find and click "Select PHP Version" or "MultiPHP INI Editor"
- Select your domain from the dropdown
- Find memory_limit
- Change the value to
256Mor higher - 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.
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:
- Shared hosting with limits: Switch to better shared hosting (SiteGround, WP Engine) or move to VPS
- Outgrown shared hosting: Upgrade to VPS or managed WordPress hosting
- VPS with low RAM: Upgrade to a plan with more server RAM
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/monthTroubleshooting: Memory Limit Still Not Increasing?
Check Which Method is Active:
Create a phpinfo() page and search for "memory_limit". It will show you:
- Local Value: What your code is trying to set (wp-config.php, .htaccess)
- Master Value: The server-wide setting (php.ini)
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:
- Audit your plugins: Deactivate plugins one by one to find memory hogs
- Use Query Monitor plugin: Identify slow database queries
- Optimize images: Use WebP format and lazy loading
- Enable caching: WP Super Cache or W3 Total Cache
- Upgrade PHP version: PHP 8.1+ is significantly more memory-efficient than 7.x
- Use object caching: Redis or Memcached for database query caching
- Limit post revisions: Add
define('WP_POST_REVISIONS', 3);to wp-config.php
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
• 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:
- Shared Hosting: 128MB-256MB (host may enforce caps)
- VPS (1GB RAM): 256MB max (leave room for other services)
- VPS (2GB+ RAM): 256MB-512MB
- VPS (4GB+ RAM): 512MB-1GB
- Dedicated Server: Whatever you need, but monitor usage
Complete Troubleshooting Checklist
- ✅ Checked current memory limit (Site Health or phpinfo)
- ✅ Added
define('WP_MEMORY_LIMIT', '256M');to wp-config.php - ✅ Cleared site cache
- ✅ Verified change in Site Health
- ✅ If not working: Edited php.ini and restarted PHP-FPM
- ✅ Tried .htaccess method (Apache only)
- ✅ Used cPanel PHP INI Editor (if available)
- ✅ Contacted hosting support
- ✅ Monitored memory usage after increase
- ✅ 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:
- Edit php.ini:
memory_limit = 256M - Restart PHP-FPM:
sudo systemctl restart php8.1-fpm - Or use cPanel PHP INI Editor
- Or contact your host
After Fixing:
- Verify the change in WordPress Site Health
- Monitor memory usage with Query Monitor
- Optimize plugins and database queries
- Only increase further if truly needed
Remember: Increasing memory is a temporary fix. For long-term stability, optimize your WordPress site, remove bloated plugins, and use caching.
✅ Increase memory limit using wp-config.php
✅ Install Query Monitor to track usage
✅ Deactivate unnecessary plugins
✅ Enable caching
✅ Monitor your site's performance