Step-by-Step Guide to Install Laravel 12 on Your Development Setup - Techvblogs

Step-by-Step Guide to Install Laravel 12 on Your Development Setup

Learn how to install Laravel 12 with ease using Composer and CLI commands.


Suresh Ramani - Author - Techvblogs
Suresh Ramani
 

1 day ago

TechvBlogs - Google News

Installing Laravel 12 on your development environment is an exciting step toward building modern, robust web applications. This comprehensive guide will walk you through everything you need to know to install Laravel 12 successfully, from system requirements to configuration and troubleshooting.

Whether you’re upgrading from an earlier version or starting fresh with Laravel development, this guide provides clear, step-by-step instructions for multiple operating systems and development environments. You’ll learn how to install Laravel 12 using various methods, configure your development setup, and get your first Laravel 12 project running smoothly.

Laravel 12 Installation Guide

Setting up Laravel 12 requires careful attention to system requirements and proper configuration. Let’s explore the different methods to install Laravel 12 and ensure your development environment is ready for this powerful PHP framework.

System Requirements for Laravel 12

Before you install Laravel 12, verify that your system meets the necessary requirements. Laravel 12 introduces enhanced features that require specific software versions for optimal performance.

Minimum System Requirements:

  • PHP: Version 8.3 or higher (PHP 8.4 recommended)
  • Composer: Version 2.0 or higher
  • Node.js: Version 18.0 or higher
  • NPM: Version 8.0 or higher
  • Memory: Minimum 2GB RAM (4GB recommended)
  • Disk Space: At least 1GB free space

Required PHP Extensions:

  • OpenSSL PHP Extension
  • PDO PHP Extension
  • Mbstring PHP Extension
  • Tokenizer PHP Extension
  • XML PHP Extension
  • Ctype PHP Extension
  • JSON PHP Extension
  • BCMath PHP Extension
  • Fileinfo PHP Extension
  • GD PHP Extension (for image processing)

Database Support: Laravel 12 supports multiple database systems:

  • MySQL 8.0+
  • PostgreSQL 12.0+
  • SQLite 3.26.0+
  • SQL Server 2017+

To check your PHP version and extensions, run:

php -v
php -m

Install Laravel 12 via Composer

The most recommended method to install Laravel 12 is through Composer, PHP’s dependency manager. This approach ensures you get the latest stable version with all necessary dependencies.

Step 1: Install Composer

If Composer isn’t installed on your system, download it from getcomposer.org.

For Windows users, download the installer. For macOS and Linux users, run:

curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer

Step 2: Install Laravel 12 Globally

Install Laravel 12 installer globally using Composer:

composer global require laravel/installer

Make sure the Composer global bin directory is in your system’s PATH. Add this line to your shell configuration file:

export PATH="$HOME/.composer/vendor/bin:$PATH"

Step 3: Create a New Laravel 12 Project

Once the installer is available globally, create a new Laravel 12 project:

laravel new my-laravel-12-app

Alternatively, you can install Laravel 12 directly through Composer without the global installer:

composer create-project laravel/laravel my-laravel-12-app

Step 4: Navigate and Start Development Server

Navigate to your project directory and start the development server:

cd my-laravel-12-app
php artisan serve

Your Laravel 12 application will be available at http://localhost:8000.

Setting Up Laravel 12 with XAMPP

XAMPP provides an easy way to install Laravel 12 on Windows, macOS, and Linux systems by providing Apache, MySQL, and PHP in a single package.

Step 1: Install XAMPP

Download XAMPP from apachefriends.org and install it with PHP 8.3 or higher.

Step 2: Start XAMPP Services

Launch XAMPP Control Panel and start:

  • Apache Web Server
  • MySQL Database

Step 3: Install Composer in XAMPP

Download Composer and install it, ensuring it uses XAMPP’s PHP installation. Update your PATH to include XAMPP’s PHP directory:

C:\xampp\php

Step 4: Install Laravel 12 in htdocs

Navigate to XAMPP’s htdocs directory and install Laravel 12:

cd C:\xampp\htdocs
composer create-project laravel/laravel laravel-12-app

Step 5: Configure Virtual Host (Optional)

Create a virtual host for cleaner URLs. Edit C:\xampp\apache\conf\extra\httpd-vhosts.conf:

<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs/laravel-12-app/public"
    ServerName laravel12.local
    <Directory "C:/xampp/htdocs/laravel-12-app/public">
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

Add this line to your hosts file (C:\Windows\System32\drivers\etc\hosts):

127.0.0.1 laravel12.local

Install Laravel 12 on Ubuntu 24.04

Ubuntu provides an excellent environment for Laravel development. Here’s how to install Laravel 12 on Ubuntu 24.04 with all necessary dependencies.

Step 1: Update System Packages

sudo apt update && sudo apt upgrade -y

Step 2: Install PHP 8.4 and Extensions

sudo apt install software-properties-common -y
sudo add-apt-repository ppa:ondrej/php -y
sudo apt update
sudo apt install php8.4 php8.4-cli php8.4-fpm php8.4-mysql php8.4-xml php8.4-curl php8.4-zip php8.4-mbstring php8.4-bcmath php8.4-gd php8.4-intl -y

Step 3: Install Composer

curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
chmod +x /usr/local/bin/composer

Step 4: Install Node.js and NPM

curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt install nodejs -y

Step 5: Install MySQL

sudo apt install mysql-server -y
sudo mysql_secure_installation

Step 6: Install Laravel 12

composer global require laravel/installer
echo 'export PATH="$HOME/.config/composer/vendor/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
laravel new laravel-12-project

Step 7: Set Proper Permissions

cd laravel-12-project
sudo chown -R $USER:www-data storage
sudo chown -R $USER:www-data bootstrap/cache
chmod -R 775 storage
chmod -R 775 bootstrap/cache

Install Laravel 12 on Windows

Windows developers can install Laravel 12 using several approaches. Here’s the most straightforward method using Command Prompt or PowerShell.

Step 1: Install PHP

Download PHP 8.4 from windows.php.net and extract it to C:\php. Add C:\php to your system PATH.

Step 2: Configure PHP

Rename php.ini-development to php.ini and enable required extensions:

extension=curl
extension=fileinfo
extension=gd
extension=mbstring
extension=openssl
extension=pdo_mysql
extension=pdo_sqlite
extension=zip

Step 3: Install Composer

Download and run the Composer installer from getcomposer.org.

Step 4: Install Node.js

Download Node.js from nodejs.org and install the LTS version.

Step 5: Install Laravel 12

Open Command Prompt or PowerShell and run:

composer global require laravel/installer

Add Composer’s global bin directory to your PATH:

%APPDATA%\Composer\vendor\bin

Create a new Laravel 12 project:

laravel new my-laravel-12-app
cd my-laravel-12-app
php artisan serve

Laravel 12 Configuration

Proper configuration is essential for Laravel 12 to function correctly. Let’s explore the key configuration steps you need to complete after installation.

Configure .env File in Laravel 12

The .env file contains environment-specific configuration for your Laravel 12 application. This file is crucial for database connections, application settings, and service configurations.

Step 1: Copy Environment File

cp .env.example .env

Step 2: Generate Application Key

php artisan key:generate

Step 3: Configure Basic Settings

Edit your .env file with the following essential configurations:

APP_NAME=MyLaravel12App
APP_ENV=local
APP_KEY=base64:generated_key_here
APP_DEBUG=true
APP_URL=http://localhost:8000

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel12_db
DB_USERNAME=root
DB_PASSWORD=your_password

CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=your_app_password
MAIL_ENCRYPTION=tls

Set Up Database for Laravel 12

Database configuration is critical for Laravel 12 applications. Here’s how to set up different database systems.

MySQL Setup:

  1. Create a new database:
CREATE DATABASE laravel12_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
  1. Create a user (optional):
CREATE USER 'laravel12_user'@'localhost' IDENTIFIED BY 'secure_password';
GRANT ALL PRIVILEGES ON laravel12_db.* TO 'laravel12_user'@'localhost';
FLUSH PRIVILEGES;
  1. Update .env file:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel12_db
DB_USERNAME=laravel12_user
DB_PASSWORD=secure_password

PostgreSQL Setup:

  1. Install PostgreSQL and create database:
sudo apt install postgresql postgresql-contrib
sudo -u postgres createdb laravel12_db
  1. Configure .env:
DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=laravel12_db
DB_USERNAME=postgres
DB_PASSWORD=your_password

Test Database Connection:

php artisan migrate:status

Laravel 12 Folder Structure Explained

Understanding Laravel 12’s folder structure helps you navigate and organize your code effectively. Here’s an overview of the key directories:

Root Directory Structure:

my-laravel-12-app/
├── app/                 # Core application code
├── bootstrap/           # Framework bootstrap files
├── config/             # Configuration files
├── database/           # Database migrations and seeds
├── public/             # Web server document root
├── resources/          # Views, raw assets
├── routes/             # Route definitions
├── storage/            # Generated files, logs, cache
├── tests/              # Automated tests
├── vendor/             # Composer dependencies
├── .env                # Environment configuration
├── artisan             # Command-line interface
└── composer.json       # Dependency management

Key Directories Explained:

  • app/: Contains your application’s core code including models, controllers, and middleware
  • config/: Stores all configuration files for database, cache, mail, and other services
  • database/: Houses migrations, model factories, and database seeders
  • public/: The web server’s document root containing the entry point (index.php)
  • resources/: Contains views, language files, and uncompiled assets
  • routes/: Defines all application routes (web, API, console, channels)
  • storage/: Stores compiled Blade templates, file uploads, logs, and cache
  • tests/: Contains automated tests for your application

Laravel 12 Development Setup

Setting up an efficient development environment enhances productivity and ensures smooth Laravel 12 development workflow.

Laravel 12 with Visual Studio Code

Visual Studio Code provides excellent support for Laravel development with helpful extensions and debugging capabilities.

Essential VS Code Extensions:

  1. Laravel Extension Pack - Complete Laravel development tools
  2. PHP Intelephense - Advanced PHP language support
  3. Laravel Blade Snippets - Blade template helpers
  4. Laravel goto view - Navigate between views and controllers
  5. DotENV - Syntax highlighting for .env files

Install Extensions:

code --install-extension bmewburn.vscode-intelephense-client
code --install-extension onecentlin.laravel5-snippets
code --install-extension onecentlin.laravel-blade

Configure VS Code Settings:

Create .vscode/settings.json in your project:

{
    "php.suggest.basic": false,
    "php.validate.executablePath": "/usr/bin/php",
    "intelephense.files.maxSize": 5000000,
    "emmet.includeLanguages": {
        "blade": "html"
    },
    "files.associations": {
        "*.blade.php": "blade"
    }
}

Launch Configuration for Debugging:

Create .vscode/launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Listen for Xdebug",
            "type": "php",
            "request": "launch",
            "port": 9003,
            "pathMappings": {
                "/var/www/html": "${workspaceFolder}"
            }
        }
    ]
}

Using Laravel 12 with Docker

Docker provides a consistent development environment across different systems. Here’s how to set up Laravel 12 with Docker.

Create docker-compose.yml:

version: '3.8'

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: laravel12-app
    restart: unless-stopped
    working_dir: /var/www
    volumes:
      - ./:/var/www
    networks:
      - laravel12

  nginx:
    image: nginx:alpine
    container_name: laravel12-nginx
    restart: unless-stopped
    ports:
      - "8000:80"
    volumes:
      - ./:/var/www
      - ./docker/nginx:/etc/nginx/conf.d
    networks:
      - laravel12

  mysql:
    image: mysql:8.0
    container_name: laravel12-mysql
    restart: unless-stopped
    environment:
      MYSQL_DATABASE: laravel12_db
      MYSQL_ROOT_PASSWORD: root_password
      MYSQL_PASSWORD: user_password
      MYSQL_USER: laravel_user
    ports:
      - "3306:3306"
    volumes:
      - mysql_data:/var/lib/mysql
    networks:
      - laravel12

networks:
  laravel12:
    driver: bridge

volumes:
  mysql_data:
    driver: local

Create Dockerfile:

FROM php:8.4-fpm

# Install dependencies
RUN apt-get update && apt-get install -y \
    build-essential \
    libpng-dev \
    libjpeg62-turbo-dev \
    libfreetype6-dev \
    locales \
    zip \
    jpegoptim optipng pngquant gifsicle \
    vim \
    unzip \
    git \
    curl \
    libzip-dev \
    libonig-dev

# Install PHP extensions
RUN docker-php-ext-install pdo_mysql mbstring zip exif pcntl
RUN docker-php-ext-configure gd --with-freetype --with-jpeg
RUN docker-php-ext-install gd

# Install Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

# Set working directory
WORKDIR /var/www

# Copy existing application directory contents
COPY . /var/www

# Install Laravel dependencies
RUN composer install

# Set permissions
RUN chown -R www-data:www-data /var/www/storage /var/www/bootstrap/cache

EXPOSE 9000
CMD ["php-fpm"]

Start Development Environment:

docker-compose up -d
docker-compose exec app php artisan migrate

Configure Laravel 12 with NGINX and PHP 8.4

For production-like development environments, configure NGINX with PHP-FPM.

Install NGINX and PHP-FPM:

sudo apt install nginx php8.4-fpm -y

Configure NGINX Virtual Host:

Create /etc/nginx/sites-available/laravel12:

server {
    listen 80;
    server_name laravel12.local;
    root /var/www/laravel12/public;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-Content-Type-Options "nosniff";

    index index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php8.4-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}

Enable Site and Restart Services:

sudo ln -s /etc/nginx/sites-available/laravel12 /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx
sudo systemctl restart php8.4-fpm

Laravel 12 Features & Changes

Laravel 12 introduces significant improvements and new features that enhance developer productivity and application performance.

What’s New in Laravel 12

Laravel 12 brings exciting new features and improvements:

Performance Enhancements:

  • Improved Eloquent query performance
  • Enhanced caching mechanisms
  • Optimized asset compilation
  • Faster route resolution

New Features:

  • Advanced API resource transformations
  • Enhanced queue job batching
  • Improved real-time broadcasting
  • Better file storage management
  • Enhanced testing utilities

Developer Experience:

  • Improved Artisan commands
  • Better error messages and debugging
  • Enhanced IDE support
  • Streamlined configuration

Laravel 12 vs Laravel 11

Key differences between Laravel 12 and Laravel 11:

Feature Laravel 11 Laravel 12
PHP Version 8.2+ 8.3+
Performance Baseline 15% faster
New Commands Standard set Enhanced Artisan
Queue System Basic batching Advanced batching
Broadcasting WebSockets Enhanced real-time
Testing PHPUnit 10 PHPUnit 11

Deprecated Features in Laravel 12

Be aware of deprecated features when upgrading:

  • Legacy authentication scaffolding
  • Older queue connection drivers
  • Deprecated helper functions
  • Legacy broadcasting drivers

Laravel 12 Troubleshooting

Common issues and solutions when working with Laravel 12.

Fix Common Laravel 12 Installation Errors

Error: "Requirements could not be resolved"

Solution:

composer install --ignore-platform-reqs
composer update

Error: "Class ‘PDO’ not found"

Solution: Enable PDO extension in php.ini:

extension=pdo
extension=pdo_mysql

Error: "Permission denied"

Solution:

sudo chown -R $USER:www-data storage bootstrap/cache
chmod -R 775 storage bootstrap/cache

Laravel 12 Permission Issues on Linux

Set Correct Ownership:

sudo chown -R www-data:www-data /var/www/laravel12

Set Directory Permissions:

sudo find /var/www/laravel12 -type d -exec chmod 755 {} \;
sudo find /var/www/laravel12 -type f -exec chmod 644 {} \;

Set Storage Permissions:

chmod -R 775 storage
chmod -R 775 bootstrap/cache

Clear Cache & Rebuild Config in Laravel 12

Clear All Cache:

php artisan cache:clear
php artisan config:clear
php artisan route:clear
php artisan view:clear

Rebuild Configuration:

php artisan config:cache
php artisan route:cache
php artisan view:cache

Laravel 12 Deployment

Deploy your Laravel 12 application to various hosting environments.

Deploy Laravel 12 on Shared Hosting

Prepare for Deployment:

composer install --optimize-autoloader --no-dev
php artisan config:cache
php artisan route:cache
php artisan view:cache

Upload Files:

  1. Upload all files except .env to your hosting directory
  2. Create .env file on server with production settings
  3. Set document root to public folder

Set Permissions:

chmod -R 755 storage bootstrap/cache

Deploy Laravel 12 to DigitalOcean

Create Droplet and Install Dependencies:

# Update system
sudo apt update && sudo apt upgrade -y

# Install LEMP stack
sudo apt install nginx mysql-server php8.4-fpm php8.4-mysql -y

# Clone repository
git clone your-repository.git /var/www/laravel12
cd /var/www/laravel12

# Install dependencies
composer install --optimize-autoloader --no-dev
npm install && npm run build

Configure Environment:

cp .env.example .env
php artisan key:generate
php artisan migrate --force

Deploy Laravel 12 on Apache and NGINX

Apache Configuration:

<VirtualHost *:80>
    ServerName yourdomain.com
    DocumentRoot /var/www/laravel12/public
    
    <Directory /var/www/laravel12/public>
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

NGINX Configuration:

server {
    listen 80;
    server_name yourdomain.com;
    root /var/www/laravel12/public;
    
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
    
    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php8.4-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

Key Takeaways

Installing Laravel 12 successfully requires attention to system requirements, proper configuration, and understanding of the framework’s structure. Whether you choose to install Laravel 12 via Composer, use Docker for containerized development, or set up traditional server environments, following these guidelines ensures a smooth installation process.

Essential steps for Laravel 12 installation:

  • Verify system requirements including PHP 8.3+ and required extensions
  • Use Composer for dependency management and Laravel installation
  • Configure your .env file with appropriate database and application settings
  • Set proper file permissions for storage and cache directories
  • Choose the development environment that best fits your workflow

Best practices for Laravel 12 development:

  • Use version control (Git) from the beginning of your project
  • Set up proper IDE configuration for enhanced productivity
  • Implement automated testing from early development stages
  • Configure caching and optimization for better performance
  • Keep dependencies updated and security patches current

By following this comprehensive guide, you’ll have a fully functional Laravel 12 installation ready for building modern web applications with confidence and efficiency.

Comments (0)

Comment


Note: All Input Fields are required.