Fixing the PHP Error: Allowed memory size of X bytes exhausted

Evans

Last Update pre 2 meseca

❗ What This Error Means

The error message:

…indicates that your PHP script has tried to use more memory than the server's PHP configuration allows.

This typically occurs on resource-intensive sites (e.g., WordPress, Magento, large uploads, or image processing) and may affect specific scripts or even cause a white screen of death (WSOD).

How to Fix It
1. Increase PHP Memory Limit via .htaccess (for Apache-based servers)

If your site uses Apache (common with cPanel and DirectAdmin), you can increase the PHP memory limit by editing the .htaccess file.

➤ Steps:
  • Open or create a .htaccess file in the root of your website (/public_html or /domains/example.com/public_html/)

  • Add the following line:

  • Save the file and reload your site.
 If the error persists, try increasing the value (e.g., 512M, 768M) or place the same line in the .htaccess file within the subdirectory where the error occurs (e.g., /folder/.htaccess).
2. Use php.ini or .user.ini (if .htaccess is not supported)

Some servers restrict using php_value in .htaccess (especially on PHP-FPM setups). In such cases, use php.ini or .user.ini.

➤ For php.ini (if supported by your hosting):
  • Create or edit a php.ini file in your website root.

  • Add:

➤ For .user.ini (common in PHP-FPM):
  • Create or edit .user.ini in your website root.

  • Add:

  • Save and wait a few minutes for the changes to apply (or restart PHP if you have control over the server).

3. Modify PHP Settings via cPanel or DirectAdmin GUI
In cPanel:
  • Go to Select PHP Version > Options (or "MultiPHP INI Editor").

  • Locate memory_limit and increase it (e.g., 256M or higher).

  • Save your changes.


In DirectAdmin:
  • Navigate to User Level > Select PHP Version or PHP Settings.

  • Find memory_limit, adjust it, and save.

4. Check for Misbehaving Scripts or Plugins

If the issue persists even after increasing memory, the root cause might be:


  • A faulty plugin/module (especially on WordPress, Joomla, or Magento)

  • A script entering an infinite loop or handling too much data

  • Recursive function calls with no exit condition

You can:

  • Enable PHP error reporting/logging to see the specific file and line

  • Disable non-essential plugins and test again

  • Review /logs/error_log in cPanel/DirectAdmin or /var/log/php-fpm.log on custom servers

Still Seeing the Error?

If none of the methods above solve the problem:


  • Check your hosting plan’s maximum memory limit (some shared plans cap it)

  • Open a support ticket 

  • Consider upgrading to a plan with more resources (e.g., VPS or dedicated hosting)

Summary

MethodLocationExample code
.htaccess/public_html/ or subfolderphp_value memory_limit 256M
php.iniWebsite rootmemory_limit = 256M
.user.iniWebsite rootmemory_limit = 256M
Panel GUIcPanel / DirectAdminAdjust via PHP Settings

Was this article helpful?

0 out of 0 liked this article

Still need help? Message Us