Install & Configure Laravel 12 from Scratch – Full Beginner Tutorial

             Laravel 12, released in February 2024, introduces a range of enhancements aimed at improving performance, developer experience, and modern PHP compatibility. Whether you're building APIs, web applications, or real-time apps, Laravel 12 continues to provide elegant solutions and developer-friendly tooling.
Here’s a look at the most notable features and updates in Laravel 12.

Laravel 12 Basic - How to Install Laravel 12 : A Step-by-Step Tutorial

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

Laravel 12 continues the framework’s tradition of thoughtful evolution — embracing modern PHP features, enhancing the developer experience, and offering first-party tools for building real-time applications. Whether you're a seasoned developer or just getting started, Laravel 12 offers plenty to get excited about.
Thinking about upgrading or starting a new project with Laravel 12? Now’s a great time.

Tags