Installing Laravel 12: A Step-by-Step Guide
Complete guide to installing Laravel 12 on your development environment. Learn system requirements, installation steps, and configuration for building modern PHP applications.
Introduction
Laravel 12 represents the latest evolution of the popular PHP framework, bringing enhanced performance, improved developer experience, and cutting-edge features to modern web development.
In this step-by-step tutorial, we'll cover everything from system requirements to running your first Laravel 12 application, ensuring you have a solid foundation for building robust web applications.
System Requirements
Before installing Laravel 12, ensure your development environment meets these requirements:
Required Software
- PHP: Version 8.3 or higher
- Composer: Version 2.0 or higher
- Node.js: Version 18.0 or higher
- NPM: Version 8.0 or higher
- Local Server: WAMP, XAMPP, or Laravel Herd
- Memory: Minimum 2GB RAM (4GB recommended)
- Disk Space: At least 1GB free space
Important: Project Location
When creating your Laravel project, make sure to place it in the correct directory based on your local server:
- XAMPP: Create project in
htdocsfolder - WAMP: Create project in
wwwfolder - Laravel Herd: Can be placed anywhere
Supported Databases
- MySQL 8.0+
- PostgreSQL 12.0+
- SQLite 3.26.0+
- SQL Server 2017+
Installation Overview
Laravel 12 can be installed using Composer, which is the most common and recommended method. We'll use Composer to create a new Laravel project in the appropriate directory for your local server setup.
The installation process involves:
- Creating the Laravel project in the correct directory
- Configuring environment variables
- Setting up the database
- Installing dependencies
- Starting the development server
Step-by-Step Installation Guide
Step 1: Verify Prerequisites
First, let's ensure all prerequisites are properly installed:
# Check PHP version
php -v
# Should show PHP 8.3 or higher
# Check Composer
composer --version
# Should show Composer 2.0 or higher
# Check Node.js
node --version
# Should show Node 18.0 or higher
# Check NPM
npm --version
# Should show NPM 8.0 or higherStep 2: Create Your Laravel Project
For XAMPP users:
# Navigate to htdocs folder
cd C:/xampp/htdocs
# Create a new Laravel 12 project
composer create-project --prefer-dist laravel/laravel blog-app "12.*"
# Navigate to the project directory
cd blog-appFor WAMP users:
# Navigate to www folder
cd C:/wamp64/www
# Create a new Laravel 12 project
composer create-project --prefer-dist laravel/laravel blog-app "12.*"
# Navigate to the project directory
cd blog-appFor Laravel Herd users:
# Create project anywhere (e.g., Desktop)
cd ~/Desktop
# Create a new Laravel 12 project
composer create-project --prefer-dist laravel/laravel blog-app "12.*"
# Navigate to the project directory
cd blog-appStep 3: Configure Environment Variables
Laravel uses environment variables for configuration. Let's set up your .env file:
# Copy the example environment file
cp .env.example .env
# Generate application key
php artisan key:generateConfigure your database in .env:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel_blog
DB_USERNAME=root
DB_PASSWORD=your_passwordStep 4: Install Dependencies
Install both PHP and Node.js dependencies:
# Install PHP dependencies (already done with composer create-project)
composer install
# Install Node.js dependencies
npm installStep 5: Set Up Database
Create your database and run migrations:
# Create database (using MySQL as example)
mysql -u root -p -e "CREATE DATABASE laravel_blog;"
# Run database migrations
php artisan migrateStep 6: Compile Frontend Assets
Laravel uses Vite for frontend asset compilation:
# Compile assets for development
npm run dev
# Or compile for production
npm run buildStep 7: Start the Development Server
# Start Laravel development server
php artisan serveYour application will be available at http://127.0.0.1:8000.
That's it! You've successfully installed your Laravel project. When you visit http://127.0.0.1:8000 in your browser, you should see the Laravel welcome page.
If you can see this page, congratulations! Your Laravel 12 installation is working perfectly and you're ready to start building your application.
Configuration and Customization
You have Laravel 12 installed on your machine by now but if you want to use a different database system, you can configure it by following the steps below.
Database Configuration
Laravel supports multiple database systems. Here are configuration examples for different databases:
MySQL Configuration:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel_blog
DB_USERNAME=root
DB_PASSWORD=your_passwordPostgreSQL Configuration:
DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=laravel_blog
DB_USERNAME=postgres
DB_PASSWORD=your_passwordSQLite Configuration:
DB_CONNECTION=sqlite
DB_DATABASE=/absolute/path/to/database.sqliteApplication Configuration
Key configuration files to review:
# Main application configuration
config/app.php
# Database configuration
config/database.php
# Cache configuration
config/cache.php
# Session configuration
config/session.phpEssential Laravel Commands
Now that you have Laravel 12 installed, here are the most commonly used commands to help you get started:
Note: You can skip this section if you want to jump straight into building your application. This is just a reference guide for when you need to use these commands.
Development Commands
# Start the development server
php artisan serve
# Run database migrations
php artisan migrate
# Create a new migration
php artisan make:migration create_posts_table
# Rollback the last migration
php artisan migrate:rollback
# Reset all migrations
php artisan migrate:resetCode Generation Commands
# Create a new controller
php artisan make:controller PostController
# Create a new model
php artisan make:model Post
# Create a model with migration
php artisan make:model Post -m
# Create a new middleware
php artisan make:middleware CheckAge
# Create a new seeder
php artisan make:seeder PostSeederCache Management
# Clear application cache
php artisan cache:clear
# Clear configuration cache
php artisan config:clear
# Clear route cache
php artisan route:clear
# Clear view cache
php artisan view:clear
# Cache configuration for better performance
php artisan config:cache
# Cache routes for better performance
php artisan route:cache
# Cache views for better performance
php artisan view:cacheDatabase Commands
# Run database seeders
php artisan db:seed
# Run a specific seeder
php artisan db:seed --class=PostSeeder
# Fresh migration with seeding
php artisan migrate:fresh --seed
# Check database connection
php artisan tinker
>>> DB::connection()->getPdo();Utility Commands
# List all available artisan commands
php artisan list
# Show application information
php artisan about
# Generate application key
php artisan key:generate
# Create a symbolic link for storage
php artisan storage:link
# Run tests
php artisan testComposer Commands
# Install dependencies
composer install
# Update dependencies
composer update
# Install a new package
composer require package/name
# Remove a package
composer remove package/name
# Optimize autoloader
composer dump-autoloadConclusion
Congratulations! You've successfully installed Laravel 12 and set up a complete development environment. You now have:
- ✅ A working Laravel 12 application
- ✅ Properly configured database connection
- ✅ Frontend asset compilation setup
- ✅ Development server running
- ✅ Understanding of common issues and solutions
Resources for Further Learning
Start building something amazing with Laravel 12! The framework's elegant syntax and powerful features will help you create applications that are both maintainable and scalable.
Happy coding!