🏠 Home / Hub

Laravel 01 — Setup & Project Structure

Get Laravel installed and understand how everything fits together before writing a single line of code.

1. Requirements

Laravel 10/11 requires the following on your machine:

ToolMinimum VersionCheck Command
PHP8.2+php -v
Composer2.xcomposer --version
MySQL / SQLite8.0 / anymysql --version
Node.js (optional)18+node -v
npm (optional)9+npm -v

Run these in your terminal to confirm everything is ready:

php -v
# PHP 8.2.x (cli)

composer --version
# Composer version 2.x

mysql --version
# mysql  Ver 8.0.x
Node.js and npm are only needed if you use Vite for compiling frontend assets (CSS/JS). For pure API or backend-only apps you can skip them.

2. Creating a New Project

Via Composer (recommended)

# Create new Laravel project called "blog_app"
composer create-project laravel/laravel blog_app

cd blog_app

# Start the built-in dev server
php artisan serve
# Server running on http://127.0.0.1:8000

Via Laravel Installer

# Install the global installer once
composer global require laravel/installer

# Then create projects faster
laravel new blog_app
cd blog_app
php artisan serve
Open http://127.0.0.1:8000 in your browser. You should see the Laravel welcome page. If you see it, your install is working correctly.

Using a different port

php artisan serve --port=8080

3. .env Configuration

The .env file in the project root holds all environment-specific settings. It is never committed to version control.

# Application
APP_NAME=BlogApp
APP_ENV=local
APP_KEY=base64:...   # auto-generated on create
APP_DEBUG=true
APP_URL=http://localhost

# Database (MySQL example)
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=blog_db
DB_USERNAME=root
DB_PASSWORD=secret

# SQLite (simpler for local dev)
# DB_CONNECTION=sqlite
# DB_DATABASE=/absolute/path/to/database.sqlite

# Mail
MAIL_MAILER=smtp
MAIL_HOST=mailpit
MAIL_PORT=1025
After changing .env, run php artisan config:clear to clear the cached config.

Generate APP_KEY

php artisan key:generate
# Application key set successfully.

4. Folder Structure

blog_app/
├── app/                   # Core application code
│   ├── Console/           # Artisan commands
│   ├── Exceptions/        # Exception handler
│   ├── Http/
│   │   ├── Controllers/   # Controller classes
│   │   ├── Middleware/    # HTTP middleware
│   │   └── Requests/      # Form request classes
│   ├── Models/            # Eloquent model classes
│   └── Providers/         # Service providers
├── bootstrap/             # App bootstrap and cache
├── config/                # All config files (app, db, mail)
├── database/
│   ├── factories/         # Model factories for testing
│   ├── migrations/        # Database schema migrations
│   └── seeders/           # Database seeders
├── public/                # Web server document root (index.php)
├── resources/
│   ├── css/               # Source CSS (compiled by Vite)
│   ├── js/                # Source JS
│   └── views/             # Blade template files (.blade.php)
├── routes/
│   ├── web.php            # Browser routes (session, CSRF)
│   ├── api.php            # API routes (stateless, /api prefix)
│   ├── console.php        # Artisan-only routes
│   └── channels.php       # Broadcast channels
├── storage/
│   ├── app/               # User-uploaded files
│   ├── framework/         # Cache, sessions, compiled views
│   └── logs/              # Application log files
├── tests/                 # PHPUnit test files
├── vendor/                # Composer packages (do not edit)
├── .env                   # Environment config (not in git)
├── composer.json          # PHP dependencies
├── package.json           # JS dependencies
└── artisan                # CLI entry point

5. Artisan Command Reference

Artisan is Laravel's command-line tool. Run php artisan list to see all commands.

CommandWhat It Does
php artisan serveStart local dev server
php artisan make:controller PostControllerCreate a controller
php artisan make:controller PostController --resourceCreate resourceful controller
php artisan make:model PostCreate an Eloquent model
php artisan make:model Post -mModel + migration together
php artisan make:migration create_posts_tableCreate a migration file
php artisan migrateRun pending migrations
php artisan migrate:rollbackUndo last migration batch
php artisan migrate:freshDrop all tables and re-migrate
php artisan db:seedRun database seeders
php artisan tinkerInteractive Laravel REPL
php artisan route:listShow all registered routes
php artisan config:cacheCache configuration files
php artisan cache:clearClear application cache
php artisan make:middleware CheckAgeCreate a middleware class
php artisan make:request StorePostRequestCreate a form request

6. App Configuration

Configuration files live in config/. The main one is config/app.php.

// config/app.php (key settings)
return [
    'name'     => env('APP_NAME', 'Laravel'),
    'env'      => env('APP_ENV', 'production'),
    'debug'    => (bool) env('APP_DEBUG', false),
    'url'      => env('APP_URL', 'http://localhost'),
    'timezone' => 'UTC',           // Change to 'Asia/Rangoon' etc.
    'locale'   => 'en',
    'key'      => env('APP_KEY'),  // Used for encryption
    'cipher'   => 'AES-256-CBC',
];

Access config values anywhere with the config() helper:

$appName  = config('app.name');      // 'BlogApp'
$timezone = config('app.timezone'); // 'UTC'
Use php artisan config:cache in production to merge all config into one cached file for faster boot times.

7. Your First Route

Open routes/web.php and add a route:

<?php
use Illuminate\Support\Facades\Route;

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

// Your first custom route
Route::get('/hello', function () {
    return '<h1>Hello, Laravel!</h1>';
});

// Return JSON
Route::get('/status', function () {
    return response()->json([
        'status'  => 'ok',
        'version' => app()->version()
    ]);
});

After saving, visit http://127.0.0.1:8000/hello — you should see "Hello, Laravel!" without restarting the server.

Changes to route files and PHP code take effect immediately — no restart needed. Only .env changes require config:clear.

8. XAMPP / Laragon Local Setup

Using XAMPP

Put your Laravel project inside C:\xampp\htdocs\ but always use php artisan serve — Apache needs public/ as its document root.

# Option A — use artisan serve (easiest)
cd C:\xampp\htdocs\blog_app
php artisan serve

# Option B — Apache virtual host (httpd-vhosts.conf)
# DocumentRoot "C:/xampp/htdocs/blog_app/public"
# <Directory "C:/xampp/htdocs/blog_app/public">
#   AllowOverride All
#   Require all granted
# </Directory>

Using Laragon (recommended on Windows)

Laragon auto-detects Laravel projects and creates a virtual host automatically. Place the project in laragon/www/ and it becomes available at http://blog_app.test.

cd C:\laragon\www
composer create-project laravel/laravel blog_app
# Browse to http://blog_app.test
Laragon bundles PHP, MySQL, Nginx, and Composer in one installer — it's the fastest way to get Laravel running on Windows.

Database Setup with XAMPP

mysql -u root -p
CREATE DATABASE blog_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
EXIT;

# Update .env:
# DB_DATABASE=blog_db
# DB_USERNAME=root
# DB_PASSWORD=      (empty for XAMPP default)

php artisan migrate   # Creates all tables

📌 Study Checklist