PHP memory limit exceeded-increase and optimize
Fix "Allowed memory size exhausted" errors. Increase PHP memory limit, identify memory hogs, optimize code.
On this page
The error "Allowed memory size of XXXXX bytes exhausted" means your WordPress or PHP application tried to use more RAM than allowed (default 128MB). Increasing the limit fixes it for most cases.
Increase PHP memory limit
For WordPress (easiest):
Edit wp-config.php and add above "That's all":
define('WP_MEMORY_LIMIT', '256M');
define('WP_MEMORY_LIMIT_MAX', '512M');
Via .htaccess:
php_value memory_limit 256M
Via cPanel (shared hosting):
- Go to Select PHP Version
- Click Switch to PHP Options
- Find memory_limit and increase to 256M
Via php.ini (VPS):
memory_limit = 256M
Check current limit
Create debug file:
<?php echo phpinfo(); ?>
Save as info.php, visit yoursite.com/info.php, search for "memory_limit".
What causes memory errors?
- Image processing: Resizing large images uses lots of RAM
- Large uploads: Processing 50MB file import
- Memory leak: Plugin with loop that never ends
- Database queries: Selecting 100,000 rows at once
- Badly written plugin: Creates unnecessary copies of data in memory
Optimize to reduce memory usage
- Compress images: Reduce file size before uploading
- Disable unused plugins: Each plugin uses RAM even if inactive
- Limit post revisions: Add to wp-config.php:
define('WP_POST_REVISIONS', 3); - Enable object caching: Reduces database queries
- Use CDN for images: Offload image serving to CloudFlare
Increasing memory limit fixes the error, but if a plugin is truly broken, it will keep growing. Find and fix the root cause or upgrade/replace the plugin.
Related: Fatal PHP errors | WordPress troubleshooting
Still troubleshooting?
Use UnderHost tools for quick checks, or open a support ticket when the issue needs account or server access.





















