Skip to main content
Magento 2

Magento 2 – Allowed memory size exhausted

By May 10, 2016No Comments

Often when setting up Magento 2 you’ll hit a memory size limit, and the error ‘Allowed memory size exhausted‘ where your local machine or hosting can’t provide sufficient memory for a script to run. This commonly occurs when trying to run large scripts, such as;

  • running migration tools
  • installing large modules
  • installing Magento
  • compiling the project
  • deploying static content

PHP Fatal error: Allowed memory size of xxx bytes exhausted

Magento 2 has memory limits defined in the root .htaccess file. These should be sufficient in production, but may cause issues when running large installation scripts when developing your site.


############################################
## adjust memory limit

    php_value memory_limit 768M
    php_value max_execution_time 18000

Allowed memory size exhausted – Solutions

Increase the memory limit in your .htaccess file

Try temporarily modifying the limits as shown above, to see if that solves your issue.


############################################
## adjust memory limit

    php_value memory_limit 1G
    php_value max_execution_time 36000

Increase the memory limit in your .php.ini file

If you have access to your php.ini file or can create one in the root, you can globally increase your allocated memory.


;adjust memory limit
memory_limit = 1G
max_execution_time = 36000
max_input_time = 36000

 

Use Composer locally

I often hit memory limits when trying to add large migration scripts to the project requirements, so I could import data from a Magento 1 website.

e.g.


php composer.phar update magento/data-migration-tool

To resolve this I ran the command in my local setup. This then added a reference to the new module to the composer.lock file. I could then copy this file up to my hosting account and run it there, using;

#update from lock file
php composer.phar install

The /vendor files for the migration tool where then downloaded from the repository without any further errors.

Let me know if this post helped you to run your Magento installation successfully, in the comments. For WordPress memory limit solutions, please refer to this post.

Andrew Taylor

A senior UI designer with over 25 years of web design and web development experience working for some of the largest companies in the UK. An expert in all things Magento and WordPress.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.