CCelestiallines.com
← Back to blog

How to Run Composer Install in Laravel 11

By Pawan Singh · Jun 2026

composer install and composer create-project get confused for each other constantly, and they do genuinely different jobs. This covers both, plus the flags and gotchas specific to Laravel 11's raised PHP baseline and deployment workflows.

Requirements

Laravel 11 raised its minimum PHP version compared to Laravel 10 — you need:

  • PHP 8.2 or higher
  • Composer 2.x
  • A database such as MySQL, MariaDB, PostgreSQL, or SQLite

Check with php -v before installing — a system still defaulting to PHP 8.1 (common on older Ubuntu LTS releases or shared hosting) will fail Laravel 11's composer.json platform requirement immediately, with an error that names the exact PHP constraint it can't satisfy.

composer install vs composer create-project

These solve different problems and it's worth being precise about which one you actually want:

  • composer create-project — scaffolds a brand-new project from a template package (in this case, laravel/laravel). You use this exactly once, when starting a project that doesn't exist yet.
  • composer install — reads an existing composer.json and composer.lock and installs the exact dependency versions they specify into vendor/. You use this every time you clone an existing Laravel project, and every time you deploy it.

The distinction matters because composer.lock pins exact versions (down to the patch level) for every dependency and sub-dependency. composer install respects that lock file exactly; composer update (a third, different command) ignores it and re-resolves everything against your version constraints, potentially pulling in newer releases. Never run composer update on a production deploy — it can silently change dependency versions in a way that hasn't been tested. Commit composer.lock to Git so every environment (your machine, a teammate's, CI, production) installs the identical dependency tree.

Starting a New Laravel 11 Project

composer create-project laravel/laravel example-app

This downloads the latest Laravel 11 release into a new example-app directory and runs composer install internally for you as part of scaffolding, pulling in every required dependency. Alternatively, install the Laravel installer globally first for a slightly nicer new-project flow:

composer global require laravel/installer
laravel new example-app

Running Composer Install on an Existing Project

This is the far more common case day-to-day: you've cloned a repo (from Git, a teammate, a deploy pipeline) that already has a composer.json and composer.lock:

composer install

Run this from the project root, next to composer.json. After it finishes, you still need the same setup steps as a fresh install — Composer only handles PHP dependencies, not the rest of the app:

cp .env.example .env
php artisan key:generate
php artisan migrate
npm install
npm run build
php artisan storage:link

Installing for Production

A production deploy should never run a plain composer install — add flags that skip development tooling and optimize the autoloader:

composer install --no-dev --optimize-autoloader
  • --no-dev — skips packages listed under require-dev (testing tools, debug bars, IDE helpers) that have no business running in production and would otherwise bloat the deploy.
  • --optimize-autoloader — generates a classmap-based autoloader instead of relying on PSR-4 lookups at runtime, which is meaningfully faster under real traffic. For the maximum version of this optimization, add --classmap-authoritative, which stops Composer's autoloader from even checking the filesystem for classes it doesn't already know about — only use this once you're confident no code dynamically requires classes outside the generated map.

Private Packages

If the project depends on a private package (a licensed tool like Laravel Nova, or a private company repository), Composer needs credentials it can't get from composer.json alone. These go in a separate, never-committed auth.json file (or the equivalent environment variables in CI), typically holding a token for Packagist's private repositories or a Git host's HTTPS token. Forgetting this file is one of the most common reasons composer install succeeds locally (where auth.json already exists from a previous setup) but fails in a fresh CI environment or on a new team member's machine.

In CI/CD Pipelines

A few habits worth adopting for any pipeline that runs composer install automatically:

  • Cache the vendor/ directory (or Composer's own cache dir) keyed on composer.lock's hash, so unchanged dependencies don't get re-downloaded on every run.
  • Run composer validate first — it catches a composer.json/composer.lock that have drifted out of sync before the actual install fails with a less obvious error.
  • Use the same PHP version in CI as production, not whatever happens to be preinstalled on the CI image — a version mismatch here is a frequent source of "works in CI, breaks in prod" surprises.

Common Issues

  • "Your requirements could not be resolved" / PHP platform requirement errors — your CLI PHP version (check with php -v) is below what Laravel 11 needs (8.2+). Note that your CLI PHP and your web server's PHP can be different versions on the same machine — check both.
  • Composer runs out of memory — prefix the command: COMPOSER_MEMORY_LIMIT=-1 composer install.
  • Private repository authentication failures — missing or expired credentials in auth.json; regenerate the token and re-run composer config or manually update the file.
  • composer.lock is out of date with composer.json — someone edited composer.json by hand without running composer update for that package; Composer will refuse to install and tell you exactly which entries are out of sync.
  • Permission errors on storage/ or bootstrap/cache/ after a fresh install — these directories need to stay writable by the web server user; a deploy script that runs as a different user can leave them owned incorrectly.
  • Ignoring platform requirements--ignore-platform-reqs exists to force an install past a PHP/extension mismatch, but it's a last resort for edge cases (e.g. building on a CI image with a different PHP than the deploy target); using it to paper over a real version mismatch usually just moves the failure to runtime instead of install time.

Need help setting up or deploying a Laravel application? I work as a freelance Laravel developer — get in touch.

Comments