Increase WordPress PHP memory limit (Allowed memory size exhausted)
Increase WordPress PHP Memory Limit (Allowed memory size exhausted)
If you encounter the “Allowed memory size exhausted” error in WordPress, it means your site has reached the maximum PHP memory allocated by your server. This limits WordPress from executing scripts properly, causing errors or white screens. The quick fix is to increase the PHP memory limit to allow WordPress more resources to run smoothly.
Quick Fix
- Edit your
wp-config.php
file located in your WordPress root directory. - Add or update the following line just before the
/* That's all, stop editing! Happy blogging. */
comment:
define('WP_MEMORY_LIMIT', '256M');
This increases the PHP memory limit to 256 megabytes, which is sufficient for most sites.
Why This Happens
WordPress runs on PHP, which has a memory limit set by your server’s PHP configuration. When a script exceeds this limit, PHP throws the “Allowed memory size exhausted” fatal error. Common causes include:
- Heavy plugins or themes consuming excessive memory.
- Large imports, backups, or media processing tasks.
- Default PHP memory limit set too low (often 32M or 64M).
- Shared hosting environments with strict memory caps.
Increasing the memory limit gives WordPress more room to operate, preventing these errors.
Step-by-step: Increase PHP Memory Limit
1. Using wp-config.php
(Recommended)
- Access your WordPress root directory via FTP, SFTP, or your hosting file manager.
- Open the
wp-config.php
file for editing. - Locate the line that says
/* That's all, stop editing! Happy blogging. */
. - Add this line right above it:
define('WP_MEMORY_LIMIT', '256M');
Save and upload the file back to the server.
2. Editing php.ini
(If you have server access)
- Locate your
php.ini
file (usually in /etc/php/ or your hosting control panel). - Open
php.ini
for editing. - Find the line starting with
memory_limit
. - Change it to:
memory_limit = 256M
- Save the file and restart your web server (Apache/Nginx) to apply changes.
3. Using .htaccess
(Apache only)
- Open the
.htaccess
file in your WordPress root directory. - Add this line at the top:
php_value memory_limit 256M
Note: This method only works if your hosting allows overriding PHP settings via .htaccess.
4. cPanel/Plesk PHP Memory Limit Adjustment
- Log in to your hosting control panel (cPanel or Plesk).
- Navigate to PHP Settings or PHP Selector.
- Find the
memory_limit
setting and increase it to256M
or higher. - Save changes and restart PHP if required.
Works on
Environment | Compatibility |
---|---|
Apache Web Server | Yes (via wp-config.php, php.ini, .htaccess) |
Nginx Web Server | Yes (via wp-config.php, php.ini) |
LiteSpeed Web Server | Yes (via wp-config.php, php.ini) |
cPanel Hosting | Yes (via PHP Selector or php.ini) |
Plesk Hosting | Yes (via PHP Settings or php.ini) |
FAQ
- Q1: How much memory should I set for WordPress PHP memory limit?
- A: 256M is a good starting point for most sites. For very large or resource-heavy sites, you may increase it to 512M or more, but check with your hosting provider first.
- Q2: What if increasing memory limit doesn’t fix the error?
- A: The error might be caused by poorly coded plugins or themes consuming excessive memory. Try disabling plugins one by one or switching to a default theme to identify the culprit.
- Q3: Can I increase memory limit via WordPress dashboard?
- A: No, WordPress dashboard does not provide an option to increase PHP memory. You must edit server or WordPress configuration files.
- Q4: Is there a risk in increasing PHP memory limit?
- A: Increasing memory limit allows scripts to use more server resources, which can impact server performance if set too high. Always increase cautiously and monitor your site’s behavior.
- Q5: My hosting provider doesn’t allow increasing memory limit. What can I do?
- A: Contact your hosting support to request a higher memory limit or consider upgrading to a hosting plan with more resources.