Laravel on Localhost

Laravel is PHP's dominant full-stack web framework — routing, Eloquent ORM, Blade templating, queues, task scheduling, broadcasting, and a clean artisan CLI all included. The built-in development server starts with php artisan serve and runs on localhost:8000. For production-like local environments, Laravel offers Herd (Mac/Windows, native), Sail (Docker-based), and Valet (Mac, Nginx-based).

Artisan dev server: localhost:8000

Quick Start — Artisan Dev Server

# Requires PHP 8.2+ and Composer
composer create-project laravel/laravel myapp
cd myapp

# Copy environment config
cp .env.example .env

# Generate application encryption key
php artisan key:generate

# Start the dev server
php artisan serve
# → App running at http://localhost:8000

Laravel Herd (Recommended for Mac/Windows)

Laravel Herd is the official local development environment for Laravel — a native app that installs PHP, Node, Nginx, and DNS resolution without Docker overhead. Any folder inside ~/Herd is automatically available at foldername.test. No Artisan serve command needed.

# Install from herd.laravel.com — then:
cd ~/Herd
composer create-project laravel/laravel myapp
# → Available at http://myapp.test automatically

Laravel Sail (Docker)

Sail is Laravel's official Docker setup — a docker-compose.yml pre-configured with PHP, MySQL, Redis, and Mailpit. Gives production-like environment, costs more startup time.

composer create-project laravel/laravel myapp
cd myapp
composer require laravel/sail --dev
php artisan sail:install   # Choose services (mysql, redis, etc.)
./vendor/bin/sail up -d    # Start all containers
# → App at http://localhost

.env — Environment Configuration

The .env file holds all environment-specific config — database, cache, mail, queue drivers. Never commit .env to git. Key settings for local development:

APP_NAME=MyApp
APP_ENV=local
APP_DEBUG=true
APP_URL=http://localhost:8000

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

CACHE_STORE=file         # Or redis for speed
QUEUE_CONNECTION=sync    # sync = jobs run immediately (good for dev)
MAIL_MAILER=log          # Logs emails instead of sending

Database Setup

# Run migrations (creates tables from migration files)
php artisan migrate

# Run migrations + seed test data
php artisan migrate:fresh --seed

# Create a new migration
php artisan make:migration create_products_table

# Rollback last migration batch
php artisan migrate:rollback

Essential Artisan Commands

CommandWhat It Does
php artisan serveStart dev server on :8000
php artisan make:model Product -mcrCreate Model + migration + controller (resourceful)
php artisan route:listList all registered routes
php artisan tinkerREPL for interacting with your app
php artisan cache:clearClear application cache
php artisan config:clearClear config cache (needed after .env changes)
php artisan queue:workProcess queued jobs
php artisan schedule:workRun scheduler in dev (polls every minute)

Frontend with Vite

Laravel uses Vite for frontend asset bundling (replacing Laravel Mix in v9+). Run Vite's dev server alongside Artisan:

# Terminal 1 — PHP backend
php artisan serve

# Terminal 2 — Vite frontend (hot reload)
npm install && npm run dev
# Vite runs at http://localhost:5173 but serves assets through Laravel's :8000

Troubleshooting

ProblemFix
APP_KEY not set errorRun php artisan key:generate
Database connection refusedMySQL must be running — start via XAMPP, Laragon, or Docker
Views not updatingphp artisan view:clear — clears compiled Blade cache
Permission denied on storage/chmod -R 775 storage bootstrap/cache on Linux/Mac
.env changes not taking effectphp artisan config:clear — Laravel caches config
Queue jobs not running in devSet QUEUE_CONNECTION=sync in .env to run jobs inline