How To Fix Allowed Memory Size of Bytes Exhausted in cPanel

How To Fix Allowed Memory Size of Bytes Exhausted in cPanel

⚠️ Fixing “Allowed Memory Size of Bytes Exhausted” in cPanel

This PHP error happens when a script consumes more memory than what is allowed by the server configuration.

Example error message:

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 4096 bytes) in /path/to/file.php on line 123

🔍 Why This Happens

  • The memory_limit in PHP is set too low.

  • Large files (images, datasets, backups) consume extra memory.

  • Too many WordPress/Drupal plugins installed.

  • Poorly optimized PHP code or memory leaks.


🛠️ Solutions

1. Increase PHP Memory Limit

Option A: Edit php.ini (root or local account)

  1. Open php.ini.

  2. Find (or add) this line:

    memory_limit = 256M
  3. Save and restart Apache/LSAPI if needed.

Option B: Edit .htaccess (in site root)

Add this line:

php_value memory_limit 256M

Option C: Use cPanel’s MultiPHP INI Editor

  1. Log into cPanel.

  2. Go to Software → MultiPHP INI Editor.

  3. Select your domain.

  4. Set:

    memory_limit = 256M
  5. Save changes.


2. Deactivate Unused Plugins (WordPress-specific)

  1. In File Manager, go to:

    public_html/wp-content/
  2. Rename the plugins folder → plugins-old.

  3. Create a new empty folder named plugins.

  4. Reload the site.

    • If it works → issue is plugin-related.

    • Restore the original folder and enable plugins one by one.


3. Optimize PHP Code

  • Free memory with unset() after using large variables:

    unset($largeArray);
  • Use pagination instead of loading large datasets at once.

  • Compress/resize images before upload.


💡 Additional Tips

  • Monitor usage with top, htop, or cPanel Resource Usage.

  • Limit memory-hogging cron jobs.

  • Keep your CMS/plugins/themes updated.

  • Always back up before applying changes.


✅ After increasing memory and optimizing, reload the site — the error should disappear.

Share

What's Your Reaction?

Like Like 0
Dislike Dislike 0
Love Love 0
Funny Funny 0
Angry Angry 0
Sad Sad 0
Wow Wow 0