Getting Started with Laravel: Your First Project (Beginner’s Guide)

Categories: Laravel

Laravel is one of the most popular PHP frameworks, loved for its elegance, simplicity, and developer-friendly features. Whether you’re building a personal blog, an e-commerce store, or a complex enterprise application, Laravel provides a clean, modern toolkit that makes development faster and more enjoyable.

In this guide, we’ll walk you through getting started with Laravel by creating your very first project — even if you’re brand new to it.


Why Choose Laravel?

Before diving into code, let’s understand why Laravel is such a big deal in the PHP world:

  • Elegant Syntax: Laravel’s code style is clean and readable.

  • Built-in Tools: Authentication, routing, caching, sessions, and more are included out of the box.

  • MVC Architecture: Clear separation of logic, data, and presentation.

  • Community Support: Thousands of packages and a vibrant developer community.

  • Scalable: Works great for small apps or enterprise-level projects.

    • *

Step 1: Setting Up Your Development Environment

Before you can create your Laravel project, you’ll need the following:

1. PHP Installed

Laravel requires PHP 8.1 or higher. You can check your version with:

php -v

2. Composer Installed

Composer is PHP’s dependency manager, and Laravel relies on it to install packages.

Download and install Composer from getcomposer.org.

Check installation:

composer -V

3. Database

You can use MySQL, PostgreSQL, SQLite, or SQL Server.
For local development, MySQL is the most common choice.


Step 2: Installing Laravel

There are two main ways to install Laravel:

Option 1: Via Composer Create-Project

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

Option 2: Via Laravel Installer

First, install the Laravel installer globally:

composer global require laravel/installer

Then create a new project:

laravel new my-first-laravel-app

Once installed, navigate into your project folder:

cd my-first-laravel-app

Step 3: Running the Laravel Development Server

Start the built-in development server with:

php artisan serve

You’ll see something like:

Laravel development server started: http://127.0.0.1:8000

Open that URL in your browser — congratulations, your Laravel app is alive! 🎉


Step 4: Understanding Laravel’s Folder Structure

When you open your Laravel project, you’ll see a lot of folders. Here’s what the most important ones do:

  • app/ → Contains the main application logic.

  • routes/ → Contains route definitions (web.php for web routes, api.php for API routes).

  • resources/views/ → Stores Blade template files (Laravel’s templating engine).

  • public/ → The publicly accessible folder (where index.php lives).

  • database/ → Holds migrations and seeders for database setup.

    • *

Step 5: Creating Your First Route

Open routes/web.php and add:

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

Visit http://127.0.0.1:8000/hello in your browser — you should see the text Hello, Laravel!


Step 6: Creating a Controller

Controllers handle request logic. Create one with Artisan:

php artisan make:controller WelcomeController

Open app/Http/Controllers/WelcomeController.php and edit:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class WelcomeController extends Controller
{
    public function index()
    {
        return view('welcome');
    }
}

Now link it in routes/web.php:

use App\Http\Controllers\WelcomeController;

Route::get('/', [WelcomeController::class, 'index']);

Step 7: Working with Blade Templates

Laravel uses Blade for templating. You’ll find the default welcome page at:

resources/views/welcome.blade.php

You can replace its HTML with your own custom design:

<!DOCTYPE html>
<html>
<head>
    <title>My First Laravel App</title>
</head>
<body>
    <h1>Welcome to My First Laravel Project</h1>
</body>
</html>

Step 8: Connecting to a Database

Edit your .env file to set database credentials:

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

Run migrations to create default tables:

php artisan migrate

Step 9: Deploying Your Laravel Project

When you’re ready to go live:

  • Upload your files to a hosting server that supports PHP 8.1+

  • Point your web server (Apache/Nginx) to Laravel’s public/ directory

  • Run composer install and php artisan migrate --force on the server

  • Set proper permissions for storage and bootstrap/cache folders

    • *

Final Tips for Beginners

  • Use php artisan commands often — it’s Laravel’s power tool.

  • Explore Laravel’s official documentation for deeper learning.

  • Always keep Laravel and PHP updated for security.

  • Practice by building small projects before tackling large applications.

    • *

Conclusion

Laravel makes PHP development a joy. By following the steps above, you’ve gone from installation to creating your first route, controller, and view. This foundation will help you explore more advanced features like authentication, API building, and Eloquent ORM for database management.

So, open your editor and start coding — your Laravel journey has just begun!


💡 Pro Tip: Bookmark this guide so you can quickly reference Laravel setup steps for future projects.