How to Set Up a New Laravel Project: Step-by-Step Guide for Beginners
Introduction
Laravel is one of the most popular PHP frameworks used by developers worldwide. Known for its elegant syntax, powerful tools, and developer-friendly features, Laravel makes it easier to build modern web applications. Whether you're just starting with PHP or switching from another framework, setting up your first Laravel project can be a smooth process when you follow the right steps.
In this step-by-step guide, we’ll walk you through the complete process of creating a new Laravel project from scratch — from installation to basic configuration — so you can get started with confidence.
Step 1: Install PHP, Composer, and Node.js
Before creating a Laravel project, make sure you have:
-
PHP >= 8.1
-
Composer installed
-
Node.js and npm (for frontend dependencies)
php -v
composer -v
node -v
npm -v
Step 2: Create a New Laravel Project
Open your terminal and run:
composer create-project laravel/laravel project-name
Replace project-name with your desired project folder name.
Alternatively, you can use Laravel Installer:
composer global require laravel/installer
laravel new project-name
Step 3: Navigate to Your Project
Go to your project directory:
cd project-name
Step 4: Serve the Application
Start Laravel’s development server:
php artisan serve
Visit http://localhost:8000 in your browser to see the Laravel welcome page.
Step 5: Configure Environment (.env)
Open .env file and set your database and app configuration:
APP_NAME=MyLaravelApp
APP_URL=http://localhost:8000
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel_db
DB_USERNAME=root
DB_PASSWORD=
Step 6: Generate App Key
Laravel requires an app key:
php artisan key:generate
This will update your .env with a secure APP_KEY.
Step 7: Run Migrations
Create database tables:
php artisan migrate
Step 8: Install Frontend Dependencies
For styling and JS (optional):
npm install
npm run dev
Step 9: Start Developing
Now your Laravel project is ready! Start creating routes, controllers, and views.
Optional Tips for Beginners
-
Use Laravel Sail for a Docker-based environment.
-
Explore Laravel Breeze or Jetstream for authentication scaffolding.
-
Always commit your
.env.exampleto version control, not.env.
Conclusion
Setting up a new Laravel project is straightforward if you follow the above steps. Once your environment is ready, you can focus on building your web application without worrying about setup issues.