WordPress PHP Memory Limit

Complete guide to understanding, increasing, and troubleshooting PHP memory limits in WordPress. Fix 'Allowed memory size exhausted' errors.

What Is PHP Memory Limit?

The PHP memory limit is a server configuration that sets the maximum amount of memory any PHP script on your website can use. This limit exists as a safeguard to prevent individual scripts from consuming excessive server resources and potentially bringing down your entire site.

When a PHP script attempts to use more memory than the allocated limit, WordPress displays a fatal error. The PHP memory limit serves as a protective boundary, ensuring that runaway scripts, infinite loops, or poorly coded plugins cannot consume all available RAM.

WordPress automatically attempts to increase the memory limit when it's set below 64MB. However, this automatic adjustment is often insufficient for modern WordPress sites.

For sites experiencing memory issues, understanding the root cause is essential. Sometimes the solution involves optimizing existing resources rather than simply allocating more memory. Our team can help diagnose whether your memory constraints stem from server configuration, plugin conflicts, or inefficient code patterns. Implementing proper WordPress maintenance routines prevents these issues from escalating.

Why Memory Limits Exist

Memory limits exist to protect both website owners and hosting providers. Without these limits, a single misbehaving script could consume all available server RAM, causing performance degradation or complete site failure for all sites on that server. Kinsta's memory limit protection explanation explains that these safeguards prevent resource monopolization and maintain stability across shared hosting environments.

Common Scenarios That Trigger Memory Exhaustion

  • Installing plugins with memory-intensive operations
  • Processing large images or media files
  • Running complex database queries
  • Exporting large amounts of data
  • Code with infinite loops or memory leaks

Understanding these triggers helps in proactive site management. If your WordPress site requires frequent memory adjustments, it may indicate a need for comprehensive performance optimization to address underlying inefficiencies rather than repeatedly increasing resource allocations. Regular AI-powered monitoring can help detect memory patterns before they cause critical errors.

Recognizing the Memory Exhausted Error

The memory exhausted error manifests in several ways, and understanding these variations helps in quick diagnosis and resolution.

Fatal Error Message

The most recognizable form of the error appears as:

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 2348617 bytes) in /path/to/site/wp-admin/includes/file.php on line 1234

This error message contains critical information: the current memory limit (33,554,432 bytes = 32MB), the attempted allocation that failed, and the specific file causing the issue.

Generic Critical Error Screen

In WordPress 5.0 and later versions, users may see a simplified error message:

"There has been a critical error on this website. Please check your site admin email inbox for instructions."

This generic message hides sensitive technical details from visitors for security purposes. The full error details are sent to the site administrator's email address.

Silent Failures

Sometimes memory exhaustion causes partial failures rather than complete crashes:

  • Pages timing out during load
  • Plugins failing to activate or update
  • Media uploads failing without clear error messages
  • Slow site performance with no obvious cause

These subtle symptoms often get overlooked. Regular WordPress maintenance can help identify and resolve these issues before they escalate into critical errors affecting your site's availability.

Methods to Increase PHP Memory Limit

There are four primary methods to increase PHP memory limit in WordPress, each with different requirements and considerations.

Method 1: Editing wp-config.php (Recommended)

The wp-config.php file is WordPress's core configuration file located in the site's root directory.

Add this line before "That's all, stop editing! Happy blogging."

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

WPBeginner's wp-config.php method provides detailed steps for safely implementing this change.

Important considerations:

  • Place the line before the stop editing comment
  • Some hosts prevent WordPress from overriding their server-level limit
  • Changes take effect immediately upon saving

Method 2: Modifying .htaccess

For sites using Apache web servers, add this line to .htaccess:

php_value memory_limit 256M

WPBeginner's .htaccess method notes that this approach requires Apache with AllowOverride enabled.

Limitations:

  • Only works on Apache servers with AllowOverride enabled
  • Some hosts restrict .htaccess modifications

Method 3: Editing php.ini

For servers with direct access, find memory_limit in php.ini:

memory_limit = 256M;

Then restart PHP for changes to take effect. Hostinger's php.ini tutorial covers locating the correct php.ini file and applying changes safely.

Method 4: Hosting Control Panel

Many hosts offer interfaces to adjust PHP settings:

  • cPanel: MultiPHP INI Editor or PHP Version selector
  • Plesk: PHP Settings within domain configuration
  • Managed WordPress: Look for PHP Memory Limit in settings Hostinger's hosting panel guide

Each method has its place depending on your hosting environment and technical access level. Our managed WordPress hosting solutions can handle these configurations for you, ensuring optimal performance and stability.

Recommended Memory Limit Values

Baseline: 128MB

A 128MB memory limit serves as a practical baseline for most standard WordPress installations. This handles typical plugin combinations and moderate media usage. Kinsta's baseline recommendations suggest starting here for simpler sites with minimal plugin requirements.

Standard: 256MB

For sites using page builders, e-commerce, or multiple plugins, 256MB represents the optimal standard allocation. Kinsta's standard allocation guidance indicates this value accommodates resource-intensive operations while maintaining server efficiency.

Consider 256MB when your site includes:

  • WooCommerce or e-commerce plugins
  • Page builders (Elementor, Divi, Beaver Builder)
  • Multiple form plugins or marketing tools
  • Large media libraries with auto-processing

Maximum: 512MB

Values above 512MB require careful justification and typically indicate underlying optimization issues. Only exceed 512MB when:

  • Specific plugin documentation explicitly requires more
  • Enterprise applications with documented high-memory workflows
  • After exhausting optimization alternatives
  • Under guidance from qualified developers

Avoid Unlimited Memory

Setting memory_limit to -1 (unlimited) creates significant security and stability risks. A single misbehaving script could consume all available server resources, affecting every site on your hosting environment. Proper resource management protects your investment and ensures consistent performance for your visitors.

For sites requiring consistent high memory allocation, consider our enterprise WordPress solutions that provide dedicated resources and optimized infrastructure.

Troubleshooting: When Increasing Memory Doesn't Work

Server-Level Restrictions Override

Hosting providers often set server-level PHP configurations that WordPress cannot override. If wp-config.php changes have no effect, the server's memory_limit is likely taking precedence.

Solutions:

Plugin Conflicts

Memory exhaustion often stems from poorly coded plugins rather than insufficient allocation.

Diagnostic approach:

  1. Deactivate all plugins
  2. Reactivate plugins one by one
  3. Monitor memory usage after each activation
  4. Identify the problematic plugin through elimination

Theme-Related Issues

Page builder themes may require more memory than simple themes. If memory issues correlate with theme changes, the theme may be the root cause.

Database Optimization

Inefficient database queries can cause memory spikes:

  1. Limit post revisions: define('WP_POST_REVISIONS', 5);
  2. Delete expired transients from the options table
  3. Optimize database tables
  4. Implement object caching

Our database optimization services can help identify and resolve these underlying issues that manifest as memory errors. Additionally, automated monitoring solutions can alert you to memory patterns before they cause downtime.

Prevention and Ongoing Monitoring

Implement Caching

Effective caching reduces peak memory usage:

  • Page caching: WP Rocket, W3 Total Cache, WP Super Cache
  • Object caching: Redis or Memcached
  • Browser caching: For static assets

Monitor Resource Usage

Regular monitoring identifies memory trends:

  • Use hosting provider's resource monitoring tools
  • Implement application performance monitoring (APM)
  • Set up alerts for resource thresholds

Optimize Images Before Upload

Large unoptimized images require significant memory:

  • Desktop: Photoshop, Affinity Photo
  • Online: TinyPNG, Squoosh
  • Plugins: Smush, Imagify

Keep WordPress Updated

WordPress core updates include performance improvements:

  • WordPress core
  • Active plugins
  • Theme framework

Limit Concurrent Operations

Prevent memory spikes from simultaneous operations:

  • Schedule automatic updates for off-peak hours
  • Limit simultaneous plugin updates
  • Use staging environments for major changes

Proactive monitoring through our WordPress maintenance plans ensures your site runs optimally while preventing memory-related issues before they impact your business. Implementing AI-driven performance insights can automate much of this monitoring.

Quick Reference: Memory Limit Methods
MethodLocationWhen to UseLimitations
wp-config.phpWordPress rootMost WordPress sitesMay be overridden by server
.htaccessServer rootApache serversRequires AllowOverride
php.iniServer configVPS or dedicatedRequires server access
Hosting PanelControl panelManaged hostingDepends on host

Conclusion

Understanding and managing PHP memory limit is essential for maintaining healthy WordPress sites:

  1. PHP memory limits exist as protective measures against resource exhaustion
  2. The memory exhausted error typically indicates a specific script or plugin issue
  3. Multiple methods exist to increase memory limits, with wp-config.php being the most common
  4. 256MB represents the optimal standard allocation for most WordPress sites
  5. Increasing memory without addressing underlying issues masks the problem

When encountering memory exhaustion, first identify the root cause before simply increasing limits. The solution often involves plugin optimization, theme adjustments, or database maintenance.

For most WordPress installations, starting with 256MB in wp-config.php provides sufficient headroom while maintaining server stability. If you consistently encounter memory issues despite optimization efforts, our web development team can help analyze your specific situation and implement lasting solutions tailored to your site's requirements. Additionally, our SEO specialists can ensure your optimized site maintains its search visibility while performing at its best.

Frequently Asked Questions

Need Help with WordPress Memory Issues?

Our team specializes in WordPress performance optimization and can diagnose memory issues, optimize your configuration, and implement lasting solutions.