Laravel Docs

Creating a Laravel 12 Project: Step-by-Step Guide

A K M Kamal Uddin

A K M Kamal Uddin

3 weeks ago 3 Minutes Read
Backend Laravel
create Laravel 12

Laravel 12 is the latest version of the popular PHP framework, offering improved performance, new features, and enhanced developer experience. Follow this comprehensive guide to set up a new Laravel 12 project from scratch.

Prerequisites

Before you begin, ensure you have:

  • PHP 8.2 or higher

  • Composer installed

  • A database server (MySQL, PostgreSQL, SQLite, or SQL Server)

  • Node.js (for frontend assets)

Step 1: Install Laravel 12

Open your terminal or command prompt and run:

If you have not installed PHP and Composer already, do it with following command

composer global require laravel/installer 

 

Then run this command-

laravel new example-app

 

When application created, run the following command-

cd example-app
npm install && npm run build
composer run dev 

 

This will:

  1. Download the latest Laravel version (currently Laravel 12)

  2. Install all required dependencies

  3. Set up the basic project structure

Step 2: Configure Environment Variables

  1. Copy the .env.example file to .env:

    cp .env.example .env
  2. Generate an application key:

    php artisan key:generate
  3. Open the .env file and configure your database connection:

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

Step 3: Run Database Migrations

Execute the default migrations to set up your database:

php artisan migrate

Step 4: Install Frontend Dependencies

Laravel uses Vite for frontend asset compilation. Install the required Node.js packages:

npm install

Step 5: Start the Development Server

You have two options to run your Laravel application:

Option 1: Use Laravel's Built-in Server

php artisan serve

This will start a development server at http://localhost:8000

Option 2: Use Sail (Docker-based)

If you prefer Docker, install Laravel Sail:

composer require laravel/sail --dev
php artisan sail:install
./vendor/bin/sail up

Step 6: Verify Your Installation

Open your browser and visit http://localhost:8000. You should see the Laravel welcome page.

Step 7: Project Structure Overview

Here are the key directories in your new Laravel 12 project:

  • app/ - Contains your application logic

  • bootstrap/ - Framework bootstrapping files

  • config/ - Configuration files

  • database/ - Migrations, factories, and seeders

  • public/ - Web-accessible directory

  • resources/ - Views, JS, CSS, and language files

  • routes/ - All application routes

  • storage/ - Logs, compiled views, and file storage

  • tests/ - PHPUnit tests

  • vendor/ - Composer dependencies

Step 8: Additional Useful Commands

  • Clear application cache:

    php artisan optimize:clear
  • Install authentication scaffolding:

    composer require laravel/ui
    php artisan ui bootstrap --auth
    npm install && npm run dev
  • Create a controller:

    php artisan make:controller ExampleController

Next Steps

Now that your Laravel 12 project is set up, consider:

  1. Setting up version control with Git

  2. Configuring your IDE for Laravel development

  3. Exploring Laravel's documentation for new features in version 12

  4. Planning your application architecture

Congratulations! You've successfully created a Laravel 12 project.

A K M Kamal Uddin

A K M Kamal Uddin

Software Developer

With over a decade of experience in web development, I have always been a huge lover of PHP, Laravel, Wordpress Development, other CMS, Javascript, Bootstrap, Tailwind CSS and Alpine JS. I am passionate about sharing my knowledge and experience with others, and I believe that learning is a lifelong journey.

Discussion (0)

Log in to comment!

No comments yet!

Releted Posts

Newsletter

Subscribe to my newsletter to get updated posts

Don't worry, I don't spam