Composer Memory Exhausted Fix

Composer memory errors usually come from dependency solving, outdated Composer versions or PHP memory limits in CLI.

Symptoms

  • composer install or update fails with allowed memory size exhausted.
  • The error happens in CLI, not the web app.
  • composer update is much worse than composer install.

Likely causes

  • CLI PHP memory_limit is too low.
  • Dependency constraints force heavy solving.
  • Composer version or lock file is outdated.

Fix steps

  1. Prefer composer install when a lock file exists.
  2. Check php -i | grep memory_limit for CLI PHP.
  3. Use COMPOSER_MEMORY_LIMIT only as a temporary diagnostic.

Verify the fix

  • Run composer diagnose.
  • Run composer install after updating Composer if needed.
  • Commit composer.lock for reproducible installs.

FAQ

Should I always set memory to -1?

No. It is a temporary workaround, not a root-cause fix.

Why does install work but update fails?

install uses the lock file, while update solves dependency versions again.

Related tools and guides

Last updated: May 18, 2026