Tutorials

Step-by-Step Guide: Setting Up a Laravel Project from Scratch

AFTAB SK October 28, 2024 2 min read 239 views
Step-by-Step Guide: Setting Up a Laravel Project from Scratch

What is Laravel?

Laravel is a popular PHP framework known for its elegant syntax and powerful features. It makes web development faster and more enjoyable.

Prerequisites

Before starting, ensure you have:

  • PHP 8.1 or higher
  • Composer installed
  • MySQL or PostgreSQL
  • Code editor (VS Code recommended)

Step 1: Install Composer

If you don't have Composer:

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php
php -r "unlink('composer-setup.php');"

Step 2: Create Laravel Project

Create a new Laravel project:

composer create-project laravel/laravel my-project
cd my-project

Step 3: Configure Environment

Copy the .env file and configure your database:

cp .env.example .env
php artisan key:generate

Update .env with your database credentials.

Step 4: Run Migrations

Set up your database:

php artisan migrate

Step 5: Start Development Server

Launch the local server:

php artisan serve

Visit http://localhost:8000 in your browser.

Step 6: Create Your First Route

Open routes/web.php and add:

Route::get('/hello', function () {
    return 'Hello, Laravel!';
});

Step 7: Create a Controller

Generate a controller:

php artisan make:controller HomeController

Next Steps

Now that your Laravel project is set up, you can:

  • Create models and migrations
  • Build views with Blade templates
  • Implement authentication
  • Add API routes

Conclusion

You've successfully set up a Laravel project! Continue learning by building features and exploring Laravel's extensive documentation.

Need a Website Like This?

Let Yolopment help you build your next project. Get started today!

Start Your Project Get Free Quote
WhatsApp
Call Us