Install & Configure Laravel 12 from Scratch – Full Beginner Tutorial

             Laravel 12, released on February 24, 2025, is a maintenance-focused upgrade from Laravel 11 with zero breaking changes, improved developer experience, and exciting additions like official React/Vue/Livewire starter kits and Laravel Reverb for real-time features. In this guide, you'll learn exactly how to install Laravel 12 from scratch, configure your environment, and launch your first application.

How to Install Laravel 12: Complete Step-by-Step Guide for Beginners

Table Of Content

1 Prerequisites

Before installing Laravel 12, ensure you have the following prerequisites installed on your system:

1. PHP ≥ 8.2

Laravel 12 requires PHP version 8.2 or higher.

Check with:

        
        php -v
        
    

If PHP is not installed, install it using Homebrew (macOS), apt/yum (Linux), or use tools like XAMPP, Laragon, or WampServer on Windows.

2. Composer

Laravel uses Composer to manage its dependencies.

Check Composer:

        
        composer -v
        
    

Install Composer: https://getcomposer.org/download/

3. Database (Optional but recommended)

You can use MySQL, PostgreSQL, SQLite, etc.
For development, MySQL is the most commonly used.

4. Node: npm uses for frontend manage its dependencies.
5. Web Server: Apache or Nginx is recommended.

2 Introduction

Here's a detailed step-by-step guide to install Laravel 12, even if you're fairly new to Laravel or PHP development. This will take you through setting up your environment, installing Laravel, and running your first app.

3 What's New in Laravel 12?

1. No More Model fillable or guarded by Default

Laravel 12 encourages using form requests and data transfer objects (DTOs) for security instead of relying on fillable or guarded.

2. Controller Route Defaults Removed
  • Default route values like ->defaults('_controller', ...) are no longer added automatically.
  • You define only what you need, keeping routes cleaner.
3. Faster Route Compilation
  • Routes now compile faster thanks to internal improvements — better performance for large apps.
4. New db:seed --class Improvements
  • You can now pass multiple seeder classes at once:
    
    php artisan db:seed --class=UserSeeder --class=PostSeeder
    
5. Laravel Reverb (Real-time Broadcasting)
  • New package for real-time apps (like chat, notifications), similar to Laravel Echo Server, but official and modern.
  • Uses WebSockets natively.
6. Improved Testing with assertDispatched
  • Easier to test queued jobs, events, and notifications using simplified assertDispatched() methods.
7. Blade Component Slots Upgraded
  • Blade slots now support named slots more cleanly and intuitively.
8. Modern Type Hinting & Return Types
  • Laravel 12 uses PHP 8.2 features, including stricter types and return types in core and stubs (generated files).
9. New when() Method on Query Builder
  • Even more elegant conditional queries:
    
    User::query()
    ->when($isActive, fn($q) => $q->where('active', 1))
    ->get();
    
10. Improved Developer Experience (DX)
  • Cleaner scaffolding
  • More expressive code generation
  • More helpful error messages

4 Create / Install a Laravel Project

4.1 Install Laravel Using Composer

Open your terminal and run:

composer create-project laravel/laravel:^12.0 my-laravel-app

Move Into the Project Directory:

cd my-laravel-app

Set File Permissions (Linux/macOS):

chmod -R 775 storage bootstrap/cache

Configure .env File
Copy the .env.example file and configure environment variables:

cp .env.example .env
php artisan key:generate

4.2 Configure MySql Database

Update the .env with your database credentials:

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

Make sure the database exists before running migrations.

Run Migrations (Optional)
If you want to create the default tables Laravel provides:

    php artisan migrate

5 Folder Structure

app/

Holds the core application code:

  • Console/ - Artisan commands
  • Exceptions/ - Custom exception handling
  • Http/ - Controllers, middleware, requests
  • Models/ - Eloquent models
  • Providers/ - Service providers

This is where most of your custom logic lives.

bootstrap/

Contains the app.php file which bootstraps the framework. The cache/ folder stores compiled files for faster loading.

config/

All your configuration files — database, queue, mail, app, etc. Each aspect of Laravel is configurable here.

database/

Organized into:

  • migrations/ - Schema definition files
  • factories/ - Model factories for testing and seeding
  • seeders/ - Seed classes to populate your database
public/

The web server points here. It contains the index.php front controller and assets like images, CSS, and JavaScript.

resources/

Where your frontend lives:

  • views/ - Blade templates
  • css/, js/ - Frontend assets (with Laravel Mix or Vite)
  • lang/ - Optional language files
  • markdown/ - If using markdown-based notifications
routes/

Contains all your route definitions:

  • web.php - Routes for web (session/cookie)
  • api.php - Stateless API routes
  • console.php - Artisan commands
  • channels.php - Broadcast channel routes
storage/

Used for file storage:

  • app/ - Local files
  • framework/ - Cached views, sessions, etc.
  • logs/ - Application logs
vendor/

Composer-managed dependencies. You don’t edit this — it's managed automatically.

Other Key Files
  • artisan - CLI tool for managing Laravel
  • composer.json - PHP dependency list
  • package.json - JS dependencies (for Vite/Mix)

6 Run Laravel Server to Test the App

Start your server with:

php artisan serve

7 Conclusion

You've successfully installed Laravel 12! Explore the official documentation at laravel.com/docs/12.x, try a starter kit, or set up Reverb for real-time features. Happy coding!
Revathi M - PHP and CodeIgniter Developer

Written by Revathi M

PHP Developer & Technical Writer · 10+ years building web applications with CodeIgniter and Laravel

Revathi specializes in PHP backend development, authentication systems, and REST API design. She writes practical, production-tested tutorials at Get Sample Code to help developers build secure applications faster.

Frequently Asked Questions

Laravel 12 requires PHP 8.2 or higher. Check your version with 'php -v'.

Run 'composer create-project laravel/laravel:^12.0 my-laravel-app' to create a new project.

You need PHP ≥ 8.2, Composer installed, an optional database like MySQL, Node.js and npm for frontend, and a web server like Apache or Nginx.

Copy '.env.example' to '.env' using 'cp .env.example .env', then update database credentials and other settings.

Run 'php artisan key:generate' after setting up the .env file.

Edit the .env file with DB_CONNECTION=mysql, DB_HOST=127.0.0.1, DB_PORT=3306, DB_DATABASE=your_database, DB_USERNAME, and DB_PASSWORD.

After configuring the database, run 'php artisan migrate' to create the default tables.

Run 'php artisan serve' from the project directory to start the server at http://localhost:8000.