What is Composer and how do I use it to install Laravel?
Composer is the standard dependency management tool for PHP, essential for installing Laravel and managing packages in any project. This guide explains what Composer is, how to install it, and how to use it to create and manage Laravel 12 projects.
What is Composer?
Composer helps PHP developers manage project dependencies efficiently. Key features include:
- Automatically installs all required packages.
- Handles version compatibility and updates.
- Generates
composer.jsonandcomposer.lockto track dependencies. - Ensures reproducible installations across different environments.
Installing Composer
Download Composer from getcomposer.org and install it globally so you can run it from any folder.
Verify the installation:
- Run
composer --version— you should see something like Composer version 2.6.5 2026-01-22
Installing Laravel Using Composer
There are two main ways to create a new Laravel project:
Option 1: Composer create-project
- Command:
composer create-project laravel/laravel my-project - Installs Laravel 12, sets up
.env, vendor dependencies, and Artisan CLI. - Start development server:
php artisan serve - Open http://127.0.0.1:8000 in your browser to see the Laravel welcome page.
Option 2: Global Laravel Installer (Recommended)
- Install globally:
composer global require laravel/installer - Create a project:
laravel new my-project - Interactive setup options:
- Choose a Starter Kit (Breeze, Jetstream, or none)
- Select Database driver (SQLite, MySQL, PostgreSQL, SQL Server)
- Choose a Testing framework (Pest or PHPUnit)
- Automatically generates
.envandAPP_KEY - This is the preferred method for modern Laravel 12+ development and works perfectly on Windows.
Managing Laravel Dependencies
- Update all dependencies:
composer update - Install dependencies after cloning a repo:
composer install - Add additional packages:
composer require vendor/package
Related Answers
Still need help?
Talk to our Laravel experts
We've handled GDPR/CCPA compliance for dozens of EU & US Laravel.
