PHP

How to Build a Laravel Project with Composer in Seconds

Updated

laravel composer

One command:

$ composer create-project laravel/laravel my-app
$ cd my-app && php artisan serve

That produced Laravel 13.25.0 here, took 10.3 seconds with a warm Composer cache, and installed 76 packages plus 33 dev packages into an 86 MB vendor/. It also writes .env, generates an APP_KEY, and creates database/database.sqlite — so php artisan serve works immediately with no database setup.

Drop --prefer-dist from the older instructions. Composer’s own help says of that flag: “Forces installation from package dist (default behavior).” It has been the default for the whole Composer 2 series and adds nothing.

create-project vs the laravel installer

The laravel installer is a separate global tool that wraps create-project and adds starter kits:

$ composer global require laravel/installer
$ laravel new my-app

Running it here with the interactive prompts declined took 11.8 seconds and produced a directory whose file list is identical to create-project‘s — the only difference in composer.json was whitespace. The installer earns its place when you want its flags: --react, --vue, --livewire, --pest, --git, --database=pgsql. For a plain skeleton the two are interchangeable, and create-project is one fewer thing to install.

The PHP version Laravel 13 requires

Laravel 13’s skeleton declares:

$ php -r '$j=json_decode(file_get_contents("composer.json"),true); echo $j["require"]["php"];'
^8.3

PHP 8.0, 8.1 and 8.2 will all be rejected by Composer at resolve time. Asking Composer what blocks 8.2 gives the list directly:

$ composer why-not php 8.2.0
laravel/laravel             -        requires php (^8.3)
laravel/framework           v13.25.0 requires php (^8.3)
laravel/pint                v1.30.5  requires php (^8.3.0)
phpunit/phpunit             12.5.33  requires php (>=8.3)
...

The part nobody mentions: your lock file is tied to your PHP version

^8.3 is what the skeleton declares. What Composer resolves depends on the PHP you resolve it with. Run the same composer why-not against 8.3 on a project created under PHP 8.5.8 and it is not empty:

$ composer why-not php 8.3.0
symfony/console          v8.1.4 requires php (>=8.4.1)
symfony/http-foundation  v8.1.4 requires php (>=8.4.1)
symfony/error-handler    v8.1.2 requires php (>=8.4.1)
...

Copy that composer.json and composer.lock to a PHP 8.3 machine and the install fails outright:

$ php83 composer.phar install
Your lock file does not contain a compatible set of packages. Please run composer update.
  Problem 1
    - symfony/clock is locked to version v8.1.0 and an update of this package was not requested.
    - symfony/clock v8.1.0 requires php >=8.4.1 -> your php version (8.3.31) does not satisfy that requirement.

Laravel 13 itself is fine on 8.3 — running create-project with PHP 8.3.31 resolves a different, older Symfony and works:

$ php83 composer.phar create-project laravel/laravel lv83
laravel/framework            v13.25.0  (requires php ^8.3)
symfony/console              v7.4.16   (requires php >=8.2)
symfony/http-foundation      v7.4.16   (requires php >=8.2)

The practical rule: generate your lock file on the same PHP version your servers and CI run. A lock built on a developer’s newer PHP is not portable downward, and the error appears in CI rather than on the laptop that created it. To check which framework version a given checkout actually resolved to, see how to check your Laravel version.

What a fresh skeleton actually contains in 2026

Older guides describe files that are no longer there. Verified against a directory created minutes before this was written:

docker-compose.yml           ABSENT
resources/js/bootstrap.js    ABSENT
app/Http/Kernel.php          ABSENT
bootstrap/app.php            EXISTS
vite.config.js               EXISTS
$ cat package.json
{
    "private": true,
    "type": "module",
    "scripts": { "build": "vite build", "dev": "vite" },
    "devDependencies": {
        "@tailwindcss/vite": "^4.0.0",
        "concurrently": "^9.0.1",
        "laravel-vite-plugin": "^3.1",
        "tailwindcss": "^4.0.0",
        "vite": "^8.0.0"
    }
}

No axios, no jQuery, no resources/js/bootstrap.js to import them from. And Laravel Sail is not in require-dev:

require-dev:
    fakerphp/faker         ^1.23
    laravel/pail           ^1.2.5
    laravel/pao            ^1.0.6
    laravel/pint           ^1.27
    mockery/mockery        ^1.6
    nunomaduro/collision   ^8.6
    phpunit/phpunit        ^12.5.12

Guides that tell you to run ./vendor/bin/sail up straight after create-project are describing an older skeleton; you would need composer require laravel/sail --dev first. (laravel/pao is new — “agent-optimized output for PHP testing tools”, released 2026-08-10 — which is why php artisan test now prints a machine-readable JSON line after the usual PHPUnit output. Since fakerphp/faker is here in require-dev rather than require, see the Faker page for why that matters in production.)

The generated APP_KEY and SQLite file, the ^8.3 requirement, the files absent from a fresh skeleton and Sail’s absence from require-dev are asserted by install-laravel-with-composer.sh right after it runs composer create-project; its two PHP 8.3 tests and the laravel new comparison are skipped when those binaries are missing, and the SHA-384 check needs network access.

Installing Composer itself, safely

The manual installer without a verification step is:

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php

That downloads a PHP script over the network and immediately executes it with no integrity check — do not follow that. The official procedure includes a SHA-384 comparison against the signature Composer publishes separately, and here it is running:

$ EXPECTED=$(curl -sS https://composer.github.io/installer.sig)
$ php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
$ ACTUAL=$(php -r "echo hash_file('sha384','composer-setup.php');")
expected: c8b085408188070d5f52bcfe4ecfbee5f727afa458b2573b8eaaf77b3419b0bf2768dc67c86944da1544f06fa544fd47
actual:   c8b085408188070d5f52bcfe4ecfbee5f727afa458b2573b8eaaf77b3419b0bf2768dc67c86944da1544f06fa544fd47
MATCH

Appending two bytes to the downloaded file changes the digest completely, which is the point of checking it. On macOS, Homebrew installs the same binary — byte for byte, verified by SHA-256 — and saves you the ceremony.

Photo of author
Sudhir P. founded HeatWare.com in 1999 and has built and operated it full-stack ever since; it is now used by more than 88,000 people. He writes here about the PostgreSQL, MySQL, Linux and DevOps work that keeps it running. Articles are rewritten only after the commands in them have actually been run, and the verification scripts are published alongside them so anyone can check the claims. Reach him at blog@heatware.net.