Installation & Setup

Before you write a single route, Laravel needs to be installed. The good news is that installation is simple and entirely managed through Composer, PHP's dependency manager — there is no separate "framework download" the way older PHP frameworks sometimes worked. This page walks through everything you need before installing, two different ways to actually create a project, what the generated .env file is for, why the application key matters, how to run the project locally, and how to confirm everything worked.

1. Prerequisites

RequirementWhy you need it
PHP (recent version)Modern Laravel releases require a fairly current PHP version (Laravel 10 requires PHP 8.1+, Laravel 11 requires PHP 8.2+). Always check the specific release's documentation before starting a project.
Required PHP extensionsExtensions such as Mbstring, OpenSSL, PDO, Tokenizer, XML, Ctype, JSON, and BCMath must be enabled — most standard PHP installs (including XAMPP/WAMP) already ship with these.
ComposerLaravel itself is distributed as a set of Composer packages, and every dependency you add later (packages, testing tools, etc.) is installed through Composer too.
A databaseMySQL, PostgreSQL, SQLite, or SQL Server — you don't strictly need one to install Laravel, but you'll need one almost immediately once you start building anything real.
Tip: Run php -v and composer -V in your terminal first. If either command isn't recognized, install/update that piece before continuing — every step below assumes both are already on your PATH.

2. Creating a Project via Composer

The most universal way to start a new Laravel application is Composer's create-project command. It downloads Laravel and every package it depends on into a new folder:

# from the folder where you keep your projects
composer create-project laravel/laravel example-app

This creates a new example-app/ directory containing a complete, ready-to-run Laravel application — routes, a default welcome view, configuration files, and all vendor dependencies already installed. It can take a minute or two the first time, since Composer is downloading the full framework and its dependencies.

3. Creating a Project via the Laravel Installer

Laravel also publishes a small global CLI tool — the Laravel installer — that makes starting new projects a little more convenient once installed. You install it once, globally, via Composer:

composer global require laravel/installer

After that (and after making sure Composer's global vendor/bin directory is on your PATH), you can create new projects with a shorter command that also offers interactive prompts for things like picking a starter kit or a testing framework:

laravel new example-app
Note: Both approaches produce the same end result — a fully working Laravel application folder. composer create-project works anywhere Composer works with zero extra setup; the laravel new installer is just a nicer, more guided experience once it's installed globally.

4. The .env File

Every new Laravel project ships with a .env file in its root directory. This file holds environment-specific configuration — settings that are expected to differ between your local machine, a staging server, and production — so they're kept out of your actual PHP code entirely. Typical values stored here include:

APP_NAME=Example App
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=example_app
DB_USERNAME=root
DB_PASSWORD=

Laravel's configuration files (inside config/) read most of their values from these environment variables using the env() helper, so changing behavior between environments is usually just a matter of editing .env — no code changes required.

Never commit .env to version control. It typically contains real database credentials and other secrets specific to one machine or server. This is exactly why every Laravel project also ships a .env.example file — a safe, secret-free template of the same keys — which is meant to be committed, so other developers (or your future self) know which variables need to be set.

5. The Application Key

Notice the APP_KEY line above is empty by default. Laravel needs a unique, random application key to perform secure encryption — it's used under the hood to encrypt session data, signed URLs, and cookies. Without a valid key, encrypted cookies and sessions silently break in ways that are confusing to debug (users get logged out unexpectedly, encrypted values fail to decrypt, and so on).

The installer commands above normally generate this key automatically, but if you ever end up with an empty APP_KEY (for example, after copying .env.example to .env by hand), generate one with Artisan, Laravel's command-line tool:

php artisan key:generate

This command writes a fresh, random 32-character key straight into your .env file. Treat this key as a secret too — anyone who has it can decrypt data your application has encrypted.

6. Running the Development Server

Laravel ships with a simple built-in development server powered by PHP itself — no need to configure Apache or Nginx just to try things out locally. From inside your project folder, run:

php artisan serve

By default this starts serving your application at http://127.0.0.1:8000. You can pass --port or --host options if that default port is already in use or you need to bind to a specific address:

php artisan serve --port=8080

7. Verifying the Install

With the server running, open http://127.0.0.1:8000 in your browser. A fresh install shows Laravel's default welcome page, which confirms three things at once: PHP can run the application, your .env/APP_KEY setup is valid, and routing is working end to end. From here you're ready to start editing routes/web.php, which the next few lessons cover in detail.

8. An Alternative: Laravel Sail

If you'd rather not install PHP, Composer, and a database directly on your machine, Laravel also offers Sail — a lightweight, Docker-based local development environment that ships with every new Laravel project. Sail spins up containers for PHP, your database, and other services (like Redis) with a single command, so your local setup matches production more closely without installing any of those pieces natively:

./vendor/bin/sail up

Sail is entirely optional — everything in this tutorial track works the same whether you're running PHP natively or through Sail's containers. It's simply a convenient alternative setup path worth knowing about, especially on teams where everyone needs an identical environment.

Up next: Now that a project exists on disk, Directory Structure walks through exactly what got generated and where each piece of your application code belongs.