12

I noticed that Magento 2.1 manual recommends memory_limit=2G in php.ini. That is a crazy amount of memory, isn't that memory allowed per HTTP request? I doubt there is any hosting provider that provides that amount of memory for PHP scripts, and certainly makes Magento not viable for shared hosting.

Is that perhaps an amount for setup and migration? Is that amount really needed for production?

I also found in the documentation:

Set the PHP memory limit.
Our detailed recommendations are: 
Compiling code or deploying static assets, 756M 
Installing and updating Magento components from Magento Marketplace, 2G 
Testing, 2G

It doesn't mention production recommendations. What is recommended for production?

1 Answer 1

10

As the documentation snippet you found explains, 2G is the memory limit to cover all possible use cases. Some operations (particularly command-line operations like setup, testing, and compilation) can take a substantial amount of memory depending on the size and complexity of your installation.

Some things to note:

  1. memory_limit is the maximum amount of memory a given PHP request is allowed to take before it will be terminated. It is not the total amount of memory each request will take. In practice, most front-facing requests will take far less memory (probably 60 MB or less for most CMS pages, categories, products), with some outliers (checkout) taking several times more depending on integrations, customization, etc.
  2. Some servers allow you to set different memory limits for web requests versus the command line. If so, you should have a CLI limit of 2G, and a web limit of 768M or less.
  3. Magento itself tries to enforce a default 768M limit across-the-board, via rules in .htaccess and pub/.htaccess: php_value memory_limit 756M, and in .user.ini: memory_limit = 756M
  4. The 'technology stack requirements' page you probably saw regarding 2 GB minimum is talking about total system memory, not PHP memory limit. If you try running Magento2 on a virtual private server with less than 2 GB of RAM (including swap), you are going to have a bad time.
  5. A dedicated environment will always be better than shared hosting, but Magento2 does work on shared hosting. Magento worked extensively with some common hosting providers including GoDaddy to make one-click installations a reality. There are also Magento-specialized hosts like Nexcess that provide a higher level of shared service for a few dollars more.
3
  • Regarding point 4: the OP's quote from the "Required PHP Settings" document, not the tech stack requirements. devdocs.magento.com/guides/v2.1/install-gde/prereq/… They recommend testing and installing with a 2GB memory_limit.
    – Eligos
    Nov 16, 2017 at 14:59
  • I'd like to add .user.ini to the list of files that Magento uses/creates to enforce this limit. Both in the root and in pub/. Oct 1, 2018 at 15:02
  • A recommended 2G environment is significantly different than 2G per request! I can't imagine the latter being viable for a busy site. And even if command line PHP operations consume 2G that is extremely inefficient code.
    – MarkE
    Oct 9, 2018 at 19:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.