Knowledge

Composer out of memory (allowed memory size exhausted)

#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 on June 23, 2026 · 1 minute read

  1. About the error
  2. Why do I see this error
  3. Solution
  4. Make sure you're on Composer 2
  5. Add swap space (the proper fix on a small VPS)
  6. Raise the memory limit for one command
  7. Prefer require over update where you can

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.

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.

Solution

Make sure you're on Composer 2

Composer 2 cut memory use dramatically. Check and upgrade:

composer --version
composer self-update --2

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.

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

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!

Related articles

How to run PHP files

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.

Read more →

PHP Fatal error: Class "X" not found

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.

Read more →