Fixes & guides

composer install vs composer update: what each one changes, and which to run in production

composer install reproduces composer.lock; composer update rewrites it. Here is what each command does, when to use which, and a safe production deploy routine.

On this page
  1. What composer install does
  2. What composer update does
  3. Side by side
  4. A safe production routine
  5. Libraries are different
  6. Common questions

The short answer: composer install installs exactly what composer.lock says. composer update works out new versions from composer.json and rewrites composer.lock. In production and CI you almost always want install. You run update on purpose, on a branch, when you want newer dependencies.

What composer install does

  1. If composer.lock exists, Composer reads it and installs those exact versions, down to the commit hash, into vendor/.
  2. It checks the lock file still matches composer.json. If you edited composer.json without updating the lock, you get a warning: “The lock file is not up to date with the latest changes in composer.json”.
  3. If there is no lock file, install behaves like update and creates one.

Because the lock file pins everything, two machines that run composer install on the same commit get identical vendor/ directories. That is the point of committing composer.lock for applications.

What composer update does

  1. It reads the constraints in composer.json (for example "guzzlehttp/guzzle": "^7.8").
  2. It resolves the newest versions that satisfy every constraint together, including the dependencies of your dependencies.
  3. It writes the result to composer.lock and installs it.

You can limit the blast radius:

# Update one package (and nothing else)
composer update monolog/monolog

# Update one package and the dependencies it needs to move
composer update monolog/monolog --with-dependencies

# See what would change without touching anything
composer update --dry-run

Not sure what a constraint such as ^7.8 or ~2.1 actually allows? Paste it into the Composer constraint tester.

Side by side

composer install composer update
Reads composer.lock composer.json
Writes composer.lock Only if it is missing Always
Result is reproducible Yes No: depends on what was released today
Use in CI and production Yes No
Use to get new versions No Yes

A safe production routine

composer install --no-dev --prefer-dist --no-interaction --optimize-autoloader
  • --no-dev skips require-dev packages such as PHPUnit.
  • --optimize-autoloader (or -o) builds a class map, which is faster in production.
  • Run composer validate --strict and composer check-platform-reqs in CI to catch a stale lock file or a missing PHP extension before deploy.

Never run composer update on a production server. If a dependency resolves differently there, you have deployed code nobody tested.

Libraries are different

For a reusable library, the lock file only affects your own development. Projects that install your library ignore it and resolve versions from your composer.json. Many library authors still commit the lock file for reproducible CI, then add a second CI job that runs composer update --prefer-lowest to test the oldest versions their constraints allow.

Common questions

Should I commit composer.lock? For applications, yes, always. For libraries it is optional.

Why did install pick a version that is not the newest? Because the lock file says so. That is intended. Run composer outdated to see what newer versions exist.

What does composer update --lock do? It refreshes the lock file’s hash after a trivial composer.json change (such as the description) without upgrading packages.

Found a mistake or something out of date? Tell us and we will fix it. See our editorial policy.

A good place to start

What are you working on?

Tools, guides, PHP versions and the archive.

ToolJSON ↔ PHP arrayConvert JSON to a PHP array literal with short or array() syntax, or turn a PHP array back into JSON. Runs in your browser; nothing is uploaded.ToolSerialized data inspectorRead PHP serialized strings as a tree, find wrong string lengths after a search-and-replace, and rebuild them with correct byte counts. Parsed safely in your browser.ToolComposer constraint testerSee exactly which versions a Composer constraint such as ^2.1, ~1.4 or >=8.1 <8.4 allows, in plain English, and test versions against it.ToolPHP date() format builderBuild a PHP date() or DateTime::format() string with a live preview in any time zone, plus a reference for every format character.ToolPHP upgrade checklistPick your current and target PHP versions and get every breaking change, deprecation and tooling step in between, as a checklist you can copy.GuideAllowed memory size exhaustedWhat PHP's memory_limit fatal error means, how to tell a real leak from a big job, and fixes for the usual causes: loading whole tables, unbounded arrays, Composer and recursion.GuideComposer dependency conflictsA step-by-step way to read Composer's conflict output, find the package that is blocking you, and fix it without --ignore-platform-reqs or deleting the lock file.Guidecomposer install vs updatecomposer install reproduces composer.lock; composer update rewrites it. Here is what each command does, when to use which, and a safe production deploy routine.GuideComposer uses the wrong PHP versionComposer says "your php version (8.1.x) does not satisfy that requirement" when your server runs 8.3? The cause is usually the CLI binary, config.platform.php, or platform_check.php.GuideEloquent N+1 queriesHow to spot N+1 queries in Laravel, fix them with eager loading, withCount() and constrained loads, and make Laravel throw an exception the next time one slips in.GuideHeaders already sentThe warning names the file and line that produced output. Here is how to read it, the five usual culprits (BOM, whitespace, echo, warnings, closing tags) and fixes that do not just hide it.GuideWriting a talk proposalWhat reviewers look for in a call-for-papers submission: a specific title, an abstract for attendees, notes for the committee, and a talk-sized idea. With a worked example and a checklist.GuideLaravel queue jobs not runningJobs dispatched but never processed, stuck in the jobs table, or running old code? Work through the connection, the queue name, the worker, failed jobs and deploy restarts.PHP versionsWhat's new in PHP 8.4PHP 8.4 (released 21 November 2024) brought property hooks, public private(set) visibility, new without parentheses, lazy objects, an HTML5 DOM parser and array_find(). Plus the deprecations that matter.PHP versionsWhat's new in PHP 8.5PHP 8.5 (released 20 November 2025) added the |> pipe operator, a standards-compliant URI extension, clone() with property overrides, #[\NoDiscard] and array_first()/array_last().PHP versionsWhat's new in PHP 8.6PHP 8.6 was released on 19 November 2026. Partial function application, clamp(), readonly property defaults, Io\Poll and Time\Duration, plus the session and ValueError changes to check before upgrading.GuidePHP array to JSONWhy json_encode() sometimes gives you an object instead of a list, how to keep floats and slashes intact, and how to catch the silent false that malformed UTF-8 returns.GuideDuplicate webhooks in PHPWebhook providers retry, so the same event can arrive twice. Verify the signature, record the event ID with a unique key, answer fast and process in a queue: a pattern that works in plain PHP, Laravel and Symfony.GuidePHPStan baseline for legacy codeGenerate a PHPStan baseline, stop new errors from getting in, then raise the level step by step. A tested routine for old PHP codebases.GuidePSR-4 autoloadingHow PSR-4 maps namespaces to folders, how to configure it in composer.json, and why "Class not found" happens: case, typos, a stale autoloader or a namespace that does not match the path.GuideSerialized data broken after search-replaceChanging a domain name with SQL REPLACE() or sed corrupts PHP serialized strings because their byte lengths no longer match. Here is how to spot it and repair it safely.GuideUpgrade PHP with RectorUpgrade a PHP application one version at a time: pin the baseline, let Rector rewrite syntax, let PHPStan find what Rector cannot, and prove it with tests before you switch runtimes.PHP versionsSupported PHP versionsRelease, active support and end-of-life dates for every PHP version.ArchiveSunshinePHP talk archive 2013–2020Talk titles and speakers from eight years of the Miami PHP conference.ArchiveSpeaker indexEveryone who spoke at SunshinePHP, A to Z.