Skip to content
Tutorials Center
My learning

Topics

Lesson 2 of 67 ยท Getting Started

Installing Laravel and Creating a Project

Install Laravel 13 with Herd, the laravel installer or Composer, answer the starter kit prompts, run the app, and understand what happens on the first run.

Before you can write Laravel code, you need three things on your computer: PHP 8.4 or newer, Composer (PHP's package manager), and a way to serve the site. There are several paths to the same result. This lesson shows the common ones, explains the questions the installer asks, and finishes with a working application in your browser.

Nothing in the commands below can run on this website, so they are shown as read-only blocks. The runnable examples in this lesson are small PHP programs that imitate what the installer and the first run do, so you can see the logic.

Choose your environment

You have three realistic options:

  1. Laravel Herd (macOS and Windows). A desktop app that installs PHP, Nginx and Node for you and serves every project folder as project-name.test. No Docker, no manual configuration. This is the easiest start.
  2. Laravel Sail. A Docker Compose setup that runs PHP, MySQL, Redis and other services in containers. It is a good choice if you use Linux or want your whole team on identical services.
  3. Manual. Install PHP 8.4 and Composer yourself, then use the built-in development server. This works anywhere and teaches you the most.

Whichever you pick, check your tools first:

Terminal
php -v
composer --version
node -v

php -v must show 8.4 or newer. Node is needed for the front-end build (Vite), not for PHP itself.

On a machine with several PHP installations (for example an old XAMPP), the first php on your PATH may be too old. If php -v shows an older version, call the right binary explicitly or fix your PATH before going on. Composer will refuse to install Laravel on an unsupported PHP.

Creating a project

With the Laravel installer

The installer is a global Composer package:

Terminal
composer global require laravel/installer
laravel new example-app

If you use Herd, the laravel command is already available. The installer asks you a few questions, described below, then downloads the skeleton, installs dependencies, creates your .env file, generates an application key and runs the first migration.

With Composer only

You can skip the installer:

Terminal
composer create-project laravel/laravel example-app
cd example-app

This downloads the same skeleton without the interactive questions. You then choose a starter kit, tests and database yourself, by editing files or adding packages.

With Sail

Laravel's website offers a one-line script for macOS, Linux and Windows (via WSL) that creates the project and starts the containers. Afterwards, you run commands through vendor/bin/sail instead of php directly, for example vendor/bin/sail artisan migrate.

The installer's questions

laravel new is interactive. The exact wording changes between versions, but the decisions are always the same:

Question What it means
Starter kit None, or a kit with login, registration and a UI (React, Vue or Livewire).
Testing framework Pest (the default for new projects) or PHPUnit.
Database SQLite (zero setup), or MySQL, MariaDB or PostgreSQL.
Run npm install and build? Installs the front-end dependencies and compiles assets.

For learning, a good set of answers is: no starter kit, Pest, SQLite. You will add authentication yourself in later lessons, which teaches you far more than a generated login screen. See Authentication Overview and Starter Kits for when a kit is the right shortcut.

Running the application

If you use Herd, your site is already available at http://example-app.test once the folder is inside Herd's sites directory. No command is needed.

Without Herd, start PHP's built-in development server:

Terminal
php artisan serve

It prints an address, usually http://127.0.0.1:8000. Open it and you will see Laravel's welcome page. Stop the server with Ctrl+C. The front-end tooling has its own watcher:

Terminal
npm install
npm run dev

composer run dev goes further: in a fresh project it starts the PHP server, a queue worker, the log viewer and Vite together, so one terminal is enough.

What happens on the first run

Right after creation, the folder contains a file named .env. Laravel reads it to find out which environment it runs in, which database to use and what the secret application key is. The installer copies .env.example to .env and then runs:

Terminal
php artisan key:generate

This writes a long random value into APP_KEY. Laravel uses that key to encrypt cookies and sessions, so it must be set before the app serves real users, and it must never be committed to version control. A new project's .env looks roughly like this (shortened):

INI
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:...
APP_DEBUG=true
APP_URL=http://example-app.test

DB_CONNECTION=sqlite

With SQLite, the database is just a file, database/database.sqlite. The installer creates it and runs php artisan migrate, so the default tables exist from the start. Configuration is the subject of Configuration and Environments.

flowchart TD
    A["laravel new example-app"] --> B["Download skeleton"]
    B --> C["composer install"]
    C --> D["Copy .env.example to .env"]
    D --> E["php artisan key:generate"]
    E --> F["php artisan migrate (SQLite file)"]
    F --> G["npm install and build"]
    G --> H["Open the site"]

The installer automates the same steps you could run by hand.

Try it: reading a .env file

.env is plain text: one KEY=value per line, # for comments. Laravel uses a library for this, but the format is simple enough to parse yourself. This stand-in handles comments, quotes and an empty value:

PHP A tiny .env parser

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with fgets(STDIN)), it gets the next line from this box.

Notice that APP_KEY is empty. In a real project, php artisan key:generate fills it in. Laravel's key is 32 random bytes, stored as base64: followed by the encoded bytes. The next example builds one from fixed bytes, so the result is repeatable (a real key is random, never a pattern like this one):

PHP What an application key looks like

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with fgets(STDIN)), it gets the next line from this box.

In real Laravel, a missing or malformed key makes encryption fail with an error such as "No application encryption key has been specified". The fix is always php artisan key:generate.

Common problems

  • "Your PHP version does not satisfy the requirement": your active PHP is too old; see the warning above.
  • A blank page or a 500 error: check storage/logs/laravel.log, and make sure storage and bootstrap/cache are writable.
  • .test does not load: confirm the project folder is inside a path Herd serves, and that Herd is running.
  • "Vite manifest not found": run npm run dev or npm run build once.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which command creates a new Laravel project with interactive questions?

    The Laravel installer's laravel new asks about the starter kit, test framework and database. composer create-project works too, but it skips the questions.
  2. 2. What does php artisan key:generate do?

    The application key is used for encryption, so it has to be set. The command fills in APP_KEY in .env.
  3. 3. You run php artisan serve without Herd. What is it?

    It starts PHP's built-in development server, which is fine for local work but not for production.
  4. 4. Which database needs no extra software and is the easiest choice for learning?

    SQLite stores the database in a single file, so there is nothing to install or run.

Summary

  • You need PHP 8.4 or newer, Composer and Node; Herd, Sail or a manual setup provides them.
  • Create a project with laravel new (interactive) or composer create-project (plain skeleton).
  • Good learning answers are no starter kit, Pest and SQLite.
  • The first run needs a .env file and an APP_KEY from php artisan key:generate.
  • Serve locally with Herd, or with php artisan serve, and run npm run dev for assets.

Next: The Project Structure