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.
- 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.
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.
| Method | Target File / Location | Effectiveness on cPanel | Recommended For |
|---|---|---|---|
| cPanel PHP Selector (Native GUI) | cPanel -> Select PHP Version -> Options | 100% Guaranteed (Server-level) | All Alif Host Shared Customers (Best Method) |
| wp-config.php Directive | public_html/wp-config.php | Effective for WordPress core | Developers managing codebases |
| .user.ini / php.ini File | public_html/.user.ini | Effective on CGI/FastCGI servers | Custom PHP runtime environments |
| .htaccess Directive | public_html/.htaccess | Effective on standard Apache mod_php | Legacy 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_limitdropdown menu. - Select
256Mor512Mfrom 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.phpin 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_limitto 256M or 512M: Allocate sufficient memory for dynamic page builders and WooCommerce checkout operations. - Set
max_execution_timeto 300: Prevent large imports or database backups from timing out during execution. - Set
upload_max_filesizeto 64M or 128M: Enable smooth uploading of large media assets and plugin zip files. - Enable
opcachein PHP Extensions: Store precompiled script bytecode in RAM to accelerate overall PHP processing.




