Composer "Allowed memory size of X bytes exhausted" in CI
Composer's dependency solver is memory-hungry and hit PHP's memory_limit. Composer runs the CLI with no limit by default, but a low memory_limit in the CI PHP config can still cap it. Set COMPOSER_MEMORY_LIMIT=-1 to remove the cap for Composer only.
What this error means
composer install or update dies with "PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate ...)" partway through solving.
PHP Fatal error: Allowed memory size of 134217728 bytes exhausted
(tried to allocate 20480 bytes) in phar:///usr/bin/composer/.../Solver.phpCommon causes
A restrictive memory_limit in the CI PHP
The runner PHP sets a low memory_limit that Composer inherits, and a large graph exhausts it during resolution.
A large or complex dependency graph
Solving many packages with wide ranges allocates a lot of memory, exceeding the configured limit.
How to fix it
Raise the Composer memory limit
- Set
COMPOSER_MEMORY_LIMIT=-1for the composer step so PHP uses unlimited memory. - Re-run the install.
- Prefer this over editing global php.ini so only Composer is affected.
- run: composer install --no-interaction
env:
COMPOSER_MEMORY_LIMIT: -1Install from the lock without re-solving
Committing composer.lock and running composer install (not update) skips the heaviest solving work.
composer install --no-interaction --prefer-distHow to prevent it
- Set
COMPOSER_MEMORY_LIMIT=-1for composer steps in CI. - Commit composer.lock so CI installs rather than re-solves.
- Avoid running
composer updateon every CI job.