Composer out of memory (allowed memory size exhausted) - Rocketeers app

  [ Rocketeers ](/)   

[Login](https://rocketeersapp.com/login) 

 On this page

 Knowledge
---------

Composer out of memory (allowed memory size exhausted)
======================================================

### [\#PHP](https://rocketeersapp.com/knowledge/php)

Composer can run out of memory while resolving dependencies, especially on small VPSes. The real fix is usually swap space, not a bigger memory limit.

 Published by [Mark van Eijk](https://rocketeersapp.com/author/mark-van-eijk) on June 23, 2026 · 1 minute read

1. [About the error](#content-about-the-error)
2. [Why do I see this error](#content-why-do-i-see-this-error)
3. [Solution](#content-solution)
4. [Make sure you're on Composer 2](#content-make-sure-youre-on-composer-2)
5. [Add swap space (the proper fix on a small VPS)](#content-add-swap-space-the-proper-fix-on-a-small-vps)
6. [Raise the memory limit for one command](#content-raise-the-memory-limit-for-one-command)
7. [Prefer require over update where you can](#content-prefer-require-over-update-where-you-can)

[\#](#content-about-the-error "Permalink")About the error
---------------------------------------------------------

Running `composer update` or `composer require` fails with:

 ```
PHP Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate ...)

```

Dependency resolution is memory-hungry. To pick compatible versions, Composer compares every candidate version of every package against all the others, and large or conflicted dependency trees can exhaust the available memory.

[\#](#content-why-do-i-see-this-error "Permalink")Why do I see this error
-------------------------------------------------------------------------

- A big dependency tree, or `composer update` resolving everything from scratch.
- A small server with little RAM and **no swap** configured.
- An old Composer 1.x install, version 1 used far more memory than version 2.

[\#](#content-solution "Permalink")Solution
-------------------------------------------

### [\#](#content-make-sure-youre-on-composer-2 "Permalink")Make sure you're on Composer 2

Composer 2 cut memory use dramatically. Check and upgrade:

 ```
composer --version
composer self-update --2

```

### [\#](#content-add-swap-space-the-proper-fix-on-a-small-vps "Permalink")Add swap space (the proper fix on a small VPS)

If `proc_open(): fork failed` or the out-of-memory error shows up on a low-RAM server, the machine simply has no headroom. Adding swap solves it durably without raising PHP limits. See the dedicated guide on [adding swap space on Ubuntu](/add-swap-space-on-ubuntu).

### [\#](#content-raise-the-memory-limit-for-one-command "Permalink")Raise the memory limit for one command

To get unblocked immediately, run Composer with an unlimited limit just for that invocation:

 ```
COMPOSER_MEMORY_LIMIT=-1 composer update

```

Or point Composer at a php.ini with a higher limit:

 ```
php -d memory_limit=-1 /usr/local/bin/composer update

```

### [\#](#content-prefer-require-over-update-where-you-can "Permalink")Prefer require over update where you can

`composer require some/package` resolves a smaller slice of the tree than a full `composer update`, and `composer install` against an existing `composer.lock` barely uses any memory at all. On production you should only ever run `composer install`, never `update`:

 ```
composer install --no-dev --optimize-autoloader

```

### Subscribe to our newsletter

Do you want to receive regular updates with fresh and exclusive content to learn more about web development, hosting, security and performance? Subscribe now!

  Fill in your email address to receive updates  Subscribe 

#### More in [\#PHP](https://rocketeersapp.com/knowledge/php)

- [How to run PHP files](https://rocketeersapp.com/knowledge/run-php-files)
- [PHP file upload exceeds upload\_max\_filesize](https://rocketeersapp.com/knowledge/php-file-upload-exceeds-upload-max-filesize)
- [PHP Warning: Undefined array key](https://rocketeersapp.com/knowledge/undefined-array-key-php)
- [PHP Fatal error: Allowed memory size exhausted](https://rocketeersapp.com/knowledge/php-allowed-memory-size-exhausted)
- [PHP: Call to a member function on null](https://rocketeersapp.com/knowledge/call-to-a-member-function-on-null)
- [PHP Fatal error: Class "X" not found](https://rocketeersapp.com/knowledge/php-class-not-found)

 [View all 11 articles →](https://rocketeersapp.com/knowledge/php)
