Skip to main content
Support Hours: 24/7 (technical team 11 AM to 8 PM PKT)WhatsApp: +92 313 2946143
WordPress Optimization
13 min read
Updated Oct 7, 2026 • Published Sep 18, 2026

WordPress PHP Memory Limit Guide: How to Increase It Safely in cPanel

Resolve memory exhaustion errors in WordPress. Learn how to increase PHP memory limits using cPanel PHP Selector, wp-config.php,.htaccess, and php.ini.

Muhammad Anees Ur Rehman
Founder & Infrastructure Architect
Share Guide:
WordPress PHP Memory Limit Guide: How to Increase It Safely in cPanel

What Is the PHP Memory Limit and Why Does WordPress Exhaust It?

In short: To increase the PHP memory limit in WordPress, raise memory_limit in cPanel (MultiPHP INI Editor) and set WP_MEMORY_LIMIT in wp-config.php, for example to 256M. The steps below show both methods and how to check the new value.

PHP is a server-side scripting language that executes code dynamically in response to web requests. To prevent poorly coded plugins or recursive execution loops from consuming all physical RAM on a server and freezing the operating system, PHP enforces a strict memory governor: the memory_limit directive. This limit dictates the maximum volume of volatile memory a single PHP thread or script can consume during execution. When complex operations, such as importing a 10,000-product WooCommerce CSV, resizing high-resolution camera images, or compiling massive Elementor page layouts, demand more RAM than allowed, execution aborts with a fatal memory exhaustion error.

Wordpress Php Memory Limit Guide architecture and execution workflow diagram.
Figure 1: Architectural workflow and configuration sequence for wordpress php memory limit guide.
  • Fatal Error Signature: Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20971520 bytes)...
  • Single-Script Scope: The memory limit governs individual script execution, not the total memory consumed by all simultaneous website visitors.
  • Legacy Defaults: Older hosting configurations set memory limits to 64MB or 128MB, which is completely insufficient for modern feature-rich CMS stacks.
Key Takeaway: Increasing your PHP memory limit grants dynamic scripts sufficient RAM to process heavy database queries and image transforms without crashing into fatal memory exhaustion ceilings. Adjust runtime allocations using our cPanel PHP configuration guide, deploy on WordPress hosting, and review CloudLinux LVE limits.

Recommended PHP Memory Allocations by Workload Type

Allocating too little memory causes frequent crashes; allocating excessive memory on an inefficient site can mask memory leaks. Match your limits to your actual software workload:

  • Standard Informational Blog / Corporate Site: 128MB is typically sufficient for lightweight themes and basic contact form plugins.
  • Dynamic Site with Page Builders (Elementor / Divi): 256MB is the recommended baseline to prevent editor canvas crashes.
  • WooCommerce E-Commerce Store with Multiple Extensions: 512MB is the industry standard to ensure smooth checkout flows and PDF invoice generation.
  • Large Multi-Site Networks or Heavy Data Importers: 768MB to 1024MB on high-tier CloudLinux shared or VPS environments.

Comparison: 4 Methods to Increase PHP Memory Limit in Hosting

Review the technical methods available to increase your PHP memory limit and their hierarchy of precedence.

Wordpress Php Memory Limit Guide performance benchmark and optimization matrix.
Figure 2: Performance benchmark comparison demonstrating latency reductions and throughput gains.
MethodTarget File / LocationEffectiveness on cPanelRecommended For
cPanel PHP Selector (Native GUI)cPanel -> Select PHP Version -> Options100% Guaranteed (Server-level)All Alif Host Shared Customers (Best Method)
wp-config.php Directivepublic_html/wp-config.phpEffective for WordPress coreDevelopers managing codebases
.user.ini / php.ini Filepublic_html/.user.iniEffective on CGI/FastCGI serversCustom PHP runtime environments
.htaccess Directivepublic_html/.htaccessEffective on standard Apache mod_phpLegacy servers (Deprecated on LiteSpeed)

Method 1: The Recommended Way: Using cPanel PHP Selector

On Alif Host servers, the cleanest and most reliable method is adjusting the server-level directive directly through your cPanel visual interface:

  • Log in to cPanel and open "Select PHP Version" under the Software section.
  • Switch to the "Options" tab at the top of the interface.
  • Scroll down to locate the memory_limit dropdown menu.
  • Select 256M or 512M from the available list. The change saves automatically and applies instantly.

Method 2: Updating wp-config.php

You can explicitly instruct WordPress core to request higher memory allocation from the hosting environment by adding this directive:

  • Open wp-config.php in your root web directory.
  • Add: define('WP_MEMORY_LIMIT', '256M'); directly above the /* That's all, stop editing! */ comment line.
  • For admin dashboard tasks, you can also add: define('WP_MAX_MEMORY_LIMIT', '512M');.

How to Verify Your Active PHP Memory Limit inside WordPress

Never assume configuration changes succeeded without verification. In your WordPress admin dashboard, navigate to Tools -> Site Health -> Info -> Server. Inspect the "PHP memory limit" value to confirm your new allocation is actively recognized.

How PHP Garbage Collection Operates and Why Memory Leaks Occur

To manage memory efficiently, PHP employs an automated cyclical garbage collector (Zend Memory Manager). When PHP scripts create variables, database query result sets, or large image buffers, memory is allocated from the system pool. Once functions return, the garbage collector frees this RAM. However, poorly written plugins containing circular object references or infinite loops prevent memory from being released, causing memory usage to climb steadily until hitting the memory_limit ceiling.

  • Circular References: Complex plugins with interdependent classes can trap memory buffers in active states.
  • Batch Processing Best Practices: Developers executing large imports should invoke wp_cache_flush() periodically to clear object memory during long-running tasks.

Profiling Memory Consumption Using Query Monitor and APM Tools

Rather than blindly increasing memory to gigabyte levels, identify which specific plugins are consuming RAM. Install the free Query Monitor plugin to view per-page memory allocation, database query execution times, and memory consumption broken down by individual active plugins.

Tuning OPcache Memory Consumption in cPanel

In addition to script memory, ensure opcache.memory_consumption is allocated at least 128MB or 256MB in your cPanel PHP options. This ensures compiled PHP script bytecode resides in server memory without overflowing into disk swap.

PHP Resource Health Checklist: Auditing Server Memory Configuration

Ensure your hosting environment is properly balanced to prevent memory exhaustion and execution timeouts:

  • Set memory_limit to 256M or 512M: Allocate sufficient memory for dynamic page builders and WooCommerce checkout operations.
  • Set max_execution_time to 300: Prevent large imports or database backups from timing out during execution.
  • Set upload_max_filesize to 64M or 128M: Enable smooth uploading of large media assets and plugin zip files.
  • Enable opcache in PHP Extensions: Store precompiled script bytecode in RAM to accelerate overall PHP processing.
Frequently Asked Questions

Common Questions Answered

Why doesn't changing wp-config.php increase my memory limit?

WordPress cannot override physical server constraints. If your server-level php.ini or CloudLinux LVE limits memory to 128M, setting define('WP_MEMORY_LIMIT', '512M'); will be ignored by the operating system.

Does increasing PHP memory limit make my website load faster?

Not directly. Memory limit is a ceiling, not an engine accelerator. However, it prevents fatal crashes during memory-intensive database queries and dynamic script executions.

Can I set memory limit to -1 (unlimited)?

Never in production! Setting memory limit to unlimited allows a single buggy script to consume 100% of server RAM, triggering an Out-of-Memory kernel crash.

What is the difference between WP_MEMORY_LIMIT and WP_MAX_MEMORY_LIMIT?

WP_MEMORY_LIMIT applies to public frontend visitor requests. WP_MAX_MEMORY_LIMIT applies specifically to backend administrative tasks in /wp-admin/ (such as importing data or updating plugins).

What happens if my allocated PHP memory exceeds my CloudLinux physical memory?

Your PHP memory_limit is a software ceiling, but CloudLinux physical memory (PMEM) is the hard hardware container limit. If your PHP script demands 512M but your hosting account PMEM is only 1GB, running two concurrent memory-heavy scripts simultaneously will trigger a 508 or 503 error.

Can I monitor real-time memory usage in cPanel?

Yes! Check the "Resource Usage" metrics inside your cPanel dashboard to monitor real-time physical memory (PMEM) and virtual memory consumption curves.

Can allocating too much PHP memory hurt server performance?

If poorly coded scripts contain memory leaks, setting an excessively high memory limit allows them to consume vast amounts of RAM before terminating. A limit of 256M to 512M represents the ideal balanced sweet spot.

Muhammad Anees Ur Rehman
Written & Audited By

Muhammad Anees Ur Rehman

Founder & Infrastructure Architect • 3+ Years Experience

Muhammad Anees Ur Rehman is the Founder and Chief Infrastructure Architect at Alif Host. With 3+ years of hands-on work in Linux web hosting, LiteSpeed server optimization, and cloud virtualization, Anees builds and runs the hosting infrastructure behind Alif Host for Pakistani businesses, e-commerce stores, and digital agencies. A staunch advocate for transparent hosting policies and local payment integration (JazzCash, Easypaisa, Raast), he regularly publishes deep-dive technical benchmarks on server response times, WordPress performance, and cyber resiliency.

LiteSpeed Web Server TuningKVM Cloud VirtualizationcPanel & WebHost Manager (WHM)
View Full Author Profile & Articles
Featured Hosting & Infrastructure

Related Hosting & Infrastructure Solutions

Free .COM on AnnualStarting at PKR 400/month

WordPress Hosting in Pakistan with LiteSpeed Cache

Optimized WordPress hosting engineered with LiteSpeed server caching, 1-click Softaculous install, free AutoSSL, and automated malware isolation.

WordPress Hosting in Pakistan with LiteSpeed Cache
Transparent PKR PricingPlans from PKR 300/month

Web Hosting Price in Pakistan: Plans in PKR

Compare web hosting plans and prices in Pakistani Rupees, with cPanel, free SSL and free migration on selected plans.

Web Hosting Price in Pakistan: Plans in PKR

Related Educational Articles

Back to Blog