Your First Laravel Project: Installation and Directory Structure Explained

Published on November 03, 2025
Laravel PHP WebDevelopment Tutorial Beginner Installation

Prerequisites: What You Need Before Starting

Before installing Laravel, ensure you have:

  • PHP (8.1 or higher)
  • Composer (Dependency Manager for PHP)
  • Database (MySQL, PostgreSQL, or SQLite)
  • Web Server (Apache/Nginx or use Laravel's built-in server)

Method 1: Installing via Laravel Installer (Recommended)

Step 1: Install Laravel Installer via Composer

composer global require laravel/installer

Step 2: Create New Laravel Project

laravel new my-first-blog

Step 3: Navigate to Project Directory

cd my-first-blog

Step 4: Start Development Server

php artisan serve

Visit http://localhost:8000 in your browser - you should see the Laravel welcome page!

Method 2: Installing via Composer Create-Project

composer create-project laravel/laravel teachyleaf-blog
cd teachyleaf-blog
php artisan serve

Laravel Directory Structure Explained

Once your project is created, let's explore the folder structure. This is crucial for understanding how Laravel organizes code.

my-first-blog/
├── app/
├── bootstrap/
├── config/
├── database/
├── public/
├── resources/
├── routes/
├── storage/
├── tests/
├── vendor/
└── environment files

1. app/ - The Application Core

This is where you'll spend most of your time.

app/
├── Console/          # Custom Artisan commands
├── Exceptions/       # Exception handlers
├── Http/             
│   ├── Controllers/  # All your controllers
│   ├── Middleware/   # Custom middleware
│   └── Kernel.php    # HTTP kernel
├── Models/           # Eloquent models
└── Providers/        # Service providers

Key Files:

  • app/Models/User.php - User model
  • app/Http/Controllers/Controller.php - Base controller

2. bootstrap/ - Framework Startup

Contains the app.php file that bootstraps the framework. You rarely need to touch this.

3. config/ - Configuration Files

All configuration files live here.

config/
├── app.php       # Application settings
├── auth.php      # Authentication configuration
├── database.php  # Database connections
├── mail.php      # Email settings
└── services.php  # Third-party services

Example config/app.php:

'name' => env('APP_NAME', 'Laravel'),
'env' => env('APP_ENV', 'production'),
'debug' => (bool) env('APP_DEBUG', false),

4. database/ - Database Related Files

database/
├── factories/     # Model factories for testing
├── migrations/    # Database migration files
├── seeders/       # Database seeder classes
└── .gitignore

Example migration:

// database/migrations/2014_10_12_000000_create_users_table.php
public function up()
{
    Schema::create('users', function (Blueprint $table) {
        $table->id();
        $table->string('name');
        $table->string('email')->unique();
        $table->timestamps();
    });
}

5. public/ - Web Root

This is the document root for your web server.

public/
├── index.php      # Entry point for all requests
├── css/           # Your CSS files
├── js/            # Your JavaScript files
└── storage/       # Symbolic link to storage/app/public

6. resources/ - Frontend Assets

resources/
├── css/           # CSS preprocessor files
├── js/            # JavaScript files
├── views/         # Blade templates
└── lang/          # Language files

Example Blade view:

// resources/views/welcome.blade.php
<html>
    <head>
        <title>{{ $title ?? 'My Site' }}</title>
    </head>
    <body>
        @yield('content')
    </body>
</html>

7. routes/ - Application Routes

Define your application endpoints here.

routes/
├── web.php        # Web routes (session, cookies)
├── api.php        # API routes (stateless)
├── console.php    # Artisan command routes
└── channels.php   # Broadcast channels

Example routes/web.php:

Route::get('/', function () {
    return view('welcome');
});

Route::get('/about', function () {
    return 'About Page';
});

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

8. storage/ - Storage Directory

storage/
├── app/           # Store generated files
│   └── public/    # Publicly accessible files
├── framework/     # Framework generated files
├── logs/          # Application log files
└── .gitignore

9. tests/ - Test Files

tests/
├── Unit/          # Unit tests
├── Feature/       # Feature tests
└── TestCase.php   # Base test case

Example test:

// tests/Feature/ExampleTest.php
public function test_basic_test()
{
    $response = $this->get('/');
    $response->assertStatus(200);
}

10. vendor/ - Composer Dependencies

All third-party packages installed via Composer. Never modify files here manually.

Key Configuration Files

.env - Environment Configuration

APP_NAME=TeachyLeaf Blog
APP_ENV=local
APP_KEY=base64:...
APP_DEBUG=true

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

# Never commit .env to version control!

composer.json - PHP Dependencies

{
    "require": {
        "php": "^8.1",
        "laravel/framework": "^10.10"
    },
    "require-dev": {
        "laravel/pint": "^1.0"
    }
}

Your First Code: Let's Create a Simple Page

Step 1: Create a Route

// routes/web.php
Route::get('/hello', function () {
    return 'Hello, TeachyLeaf Readers!';
});

Step 2: Create a View

// resources/views/welcome.blade.php
@extends('layouts.app')

@section('content')
    <h1>Welcome to My First Laravel App!</h1>
    <p>This is running on Laravel {{ app()->version() }}</p>
@endsection

Step 3: Test Your Application

php artisan serve

Visit http://localhost:8000/hello to see your message!

Common Installation Issues & Solutions

Problem: laravel command not found
Solution: Add Composer's global bin directory to your PATH

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

Problem: PHP version too low
Solution: Update PHP or use Laravel Sail (Docker)

curl -s https://laravel.build/teachyleaf-blog | bash

Problem: Permission errors
Solution: Fix storage and bootstrap cache permissions

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

Interview Questions & Answers

1. What's the purpose of the .env file?
The .env file stores environment-specific configuration like database credentials and API keys, keeping sensitive data out of your codebase.

2. What's the difference between resources/ and public/ directories?
resources/ contains source files (Blade templates, Sass, JS) that get compiled, while public/ contains the web-accessible assets like CSS, JS, and images.

3. Where would you put a new controller?
In the app/Http/Controllers/ directory, following PSR-4 autoloading standards.

4. What are migrations and where are they stored?
Migrations are version control for your database schema, stored in the database/migrations/ directory.

5. How do you start a Laravel development server?
Run php artisan serve from the project root directory.

Quick Start Commands Cheat Sheet

# Create new project
laravel new project-name

# Or using Composer
composer create-project laravel/laravel project-name

# Start development server
php artisan serve

# Generate application key
php artisan key:generate

# Run migrations
php artisan migrate

# Clear configuration cache
php artisan config:clear

Congratulations! You've set up your first Laravel project. Now that you understand the structure, our next post will dive into Laravel Routing: All You Need to Know About GET, POST, and Resource Routes where you'll learn to create application endpoints.