PHP Fatal error: Allowed memory size of 2097152 bytes exhausted (tried to allocate 12288 bytes)

PHP Fatal error: Allowed memory size of 2097152 bytes exhausted (tried to allocate 12288 bytes)

July 18, 2026 · Illustrated author avatarBy Stefan Bogdanescu
PHP Fatal error: Allowed memory size of 2097152 bytes exhausted (tried to allocate 12288 bytes)

Understanding the “Allowed Memory Size Exhausted” Error in Magento

You’re encountering a common yet frustrating issue while managing your Magento site: the “allowed memory size of 2097152 bytes exhausted” error during setup upgrade operations. This problem occurs when your PHP script attempts to allocate more memory than it’s currently permitted, leading to a fatal error.

Why Changing memory_limit in php.ini Didn’t Work

When you modified the memory_limit value in the PHP configuration file (php.ini), you likely followed the standard approach to increase PHP’s allocated memory. However, if this change didn’t resolve your issue, it’s possible that the new limit isn’t being applied for several reasons:

  1. The php.ini file might not actually be loaded: Ensure that your server is configured to use the correct php.ini file where you made changes.

  2. You may be using a PHP CLI version different from the one your application runs on: The memory limit could be defined separately for the command line interface (CLI) version of PHP and the version running in your web environment.

  3. Your server might have restrictions on changing the memory limit: Some hosting providers or server configurations prevent modifications to certain PHP settings, including memory_limit.

Alternative Solutions to Resolve the Memory Exhaustion Issue

If adjusting the memory_limit directly isn’t working, consider these alternative approaches:

  1. Use the -dmemory_limit command line flag:

You can specify the memory limit directly in your terminal when running Magento commands:

php -dmemory_limit=512M bin/magento setup:upgrade

This approach bypasses any restrictions on modifying php.ini files and allows you to set the memory limit temporarily for your specific operation.

  1. Switch to a Varnish cache with more memory:

If you’re using a caching solution like Varnish, consider increasing its memory allocation or updating to a version that supports larger caches. This can help reduce the load on PHP memory during high-traffic periods.

  1. Optimize your code and clear unnecessary data:

Review your custom extensions and third-party plugins for potential performance bottlenecks or excessive memory usage. Clear unnecessary data from your database using tools like Magento’s built-in data cleanup features (e.g., bin/magento setup:upgrade --keep-generated) to free up resources.

Conclusion: Addressing Memory Exhaustion in a Strategic Manner

When facing “allowed memory size exhausted” errors, it’s essential not only to increase the memory limit but also to identify and address the root causes of high memory usage. Optimize your code, clear unnecessary data, and consider using memory-efficient extensions.

If you’re looking for professional assistance or need help with Magento performance optimization, don’t hesitate to contact our team at https://laravelcompany.com/magento-services/. Our experts specialize in Magento development and can provide tailored solutions to resolve memory issues effectively.

API Configuration Deployment Errors

Our network