Magento 2E-CommerceHow To GuideApril 27, 2024Simon Walker

[Fixed]: Allowed Memory Size of Bytes Exhausted Magento 2

[Fixed]: Allowed Memory Size of Bytes Exhausted Magento 2

Every day you read articles or hear stories from friends and family about a person running a successful online store. Indeed, running an eCommerce store can be a financially rewarding experience. Nevertheless, the journey is not smooth, and you are bound to run into problems.

The problems range from late product deliveries to technical problems. For instance, if you are running a store in Magento 2, you are bound to encounter PHP Fatal Error “Allowed Memory Size”. The error looks something like “allowed memory size of xxxx size exhausted”.

This article discusses everything there is to know about this error, including its causes and the most appropriate fix.

Check Out Our Must-Have Extensions for Any eCommerce Store:

Cause of the Allowed Memory Size Bytes Exhausted Error

The cause of the error “allowed memory size of bytes exhausted” is obvious i.e. it’s related to shortage of memory. The error occurs if you try to use more RAM resources than what you have specified in the php.ini file through “memory_limit”. It can occur when you are running an operation using a large dataset.

For example, you are updating descriptions for thousands of products simultaneously or importing/exporting a large number of products into the database. Secondly, Magento 2 is a highly customisable platform. With extensions and custom Magento development, you can tailor each aspect to your requirements.

However, using a large number of extensions and customisations can cause you to consume large amounts of memory. It is quite common to experience the allowed memory size of bytes exhausted in such a situation. Poorly written code can also result in high memory consumption.


Remember, out of memory errors are one of the most common and hard to fix. In this case, however, the solution is simple. You just have to increase the memory limit in the php.ini file. It is the default configuration file that is used to control upload sizes, file timeouts and resource limits. This is what you have to do to resolve the error.

  • Locate php.ini file. This will usually be etc/php.ini.
  • Find the parameter memory_limt =128M
  • Increase the limit to 256M or 512M.

Increase the Memory Limit

You can also increase the memory limit using the following commands.

php -d memory_limit=1G bin/magento setup:di:compile
php -d memory_limit=1G bin/magento setup:static-content:deploy

You can change 1G to whatever limit you want. This will surely resolve the error allowed memory size of bytes exhausted in Magento 2.

Final Thoughts on Allowed Memory Size Exhausted php

While the above solutions can resolve the error, we recommend addressing the underlying issues. You must optimise your code and limit the use of extensions. In most cases, merchants use overlapping extensions. As a leading Magento development company, we can conduct a comprehensive audit of your store. contact us in case you require help in this regard or have any questions related to this article.