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.
Table Of Content
1 Prerequisites
Before installing Laravel 12, ensure you have the following prerequisites installed on your system:
1. PHP ≥ 8.2Laravel 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.
Laravel uses Composer to manage its dependencies.
Check Composer:
composer -v
Install Composer: https://getcomposer.org/download/
You can use MySQL, PostgreSQL, SQLite, etc.
For development, MySQL is the most commonly used.
5. Web Server: Apache or Nginx is recommended.
2 Introduction
3 What's New in Laravel 12?
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.
- Routes now compile faster thanks to internal improvements — better performance for large apps.
- 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.
- Easier to test queued jobs, events, and notifications using simplified assertDispatched() methods.
- Blade slots now support named slots more cleanly and intuitively.
- Laravel 12 uses PHP 8.2 features, including stricter types and return types in core and stubs (generated files).
- 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
composer create-project laravel/laravel:^12.0 my-laravel-app
cd my-laravel-app
chmod -R 775 storage bootstrap/cache
cp .env.example .env
php artisan key:generate
4.2 Configure MySql Database
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.
php artisan migrate
5 Folder Structure
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.
Contains the app.php file which bootstraps the framework. The cache/ folder stores compiled files for faster loading.
All your configuration files — database, queue, mail, app, etc. Each aspect of Laravel is configurable here.
Organized into:
- migrations/ - Schema definition files
- factories/ - Model factories for testing and seeding
- seeders/ - Seed classes to populate your database
The web server points here. It contains the index.php front controller and assets like images, CSS, and JavaScript.
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
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
Used for file storage:
- app/ - Local files
- framework/ - Cached views, sessions, etc.
- logs/ - Application logs
Composer-managed dependencies. You don’t edit this — it's managed automatically.
- 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
php artisan serve
7 Conclusion
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.
