Short answer: Add define('WP_MEMORY_LIMIT', '256M'); into wp-config.php before the stop editing line, and raise PHP memory_limit in cPanel Select PHP Version > Options.
Resolve PHP fatal memory allocation crashes in WordPress by increasing WP_MEMORY_LIMIT in wp-config.php and CloudLinux PHP Selector.
Before you start: Back up your site files and database and download the backup to your own computer. How to take a full backup
Quick reference
| wp-config.php Constant | define('WP_MEMORY_LIMIT', '512M'); |
|---|---|
| Admin Constant | define('WP_MAX_MEMORY_LIMIT', '512M'); |
| cPanel Interface | Software > Select PHP Version > Options > memory_limit |
Quick diagnosis
| Scenario & Suspected Cause | Immediate Action & Remedy |
|---|---|
| WordPress standard 40MB internal limit reached | Add define('WP_MEMORY_LIMIT', '256M'); into wp-config.php before the stop editing comment. |
| cPanel PHP runtime limit ceiling too low | Access cPanel Select PHP Version > Options tab and raise memory_limit to 512M. |
| Heavy memory overhead from page builders (Elementor) | Disable unused builder addons and optimize widget usage across templates. |
| Data import or bulk thumbnail regeneration | Temporarily elevate memory allocation to 1024M during large catalog migrations. |
Steps
- Understand the Dual Memory Limits: WordPress imposes an internal software limit (usually 40MB for frontend, 64MB for admin) which is lower than the server's actual PHP limit. Both must be increased.
- Step 1: Increase WP_MEMORY_LIMIT in wp-config.php:
- In cPanel File Manager, edit
public_html/wp-config.php. - Add the following two lines before the line that says
require_once ABSPATH . 'wp-settings.php';:define('WP_MEMORY_LIMIT', '512M'); define('WP_MAX_MEMORY_LIMIT', '512M'); - Save changes.
- In cPanel File Manager, edit
- Step 2: Increase Server PHP memory_limit in cPanel:
- Go to cPanel > Software > Select PHP Version > Options.
- Locate
memory_limitand change it to512Mor1024M.
- Verify in WooCommerce / WordPress Site Health:
- In WordPress, go to Tools > Site Health > Info > WordPress Constants.
- Confirm that
WP_MEMORY_LIMITdisplays512M.
Troubleshooting and tips
- Memory Limit Still Stuck at 40MB: If the limit does not change, your directive was placed below
require_once ABSPATH . 'wp-settings.php';where it is ignored. Move it higher up inwp-config.php.
Need more help? If you run into an error while following these steps, open a ticket with technical support and our team will look into it. Open a ticket