Introduction to Laravel and Setting Up the Development Environment
Laravel is the world's most popular PHP framework—its elegant syntax makes web development efficient and enjoyable, much like the evolution from handwritten letters to email.
1. What You'll Learn
- Laravel 11: Version Features and an Overview of the Ecosystem
- PHP 8.2+ System Requirements and the Composer Package Manager
- Docker Development Environments: Laravel Sail vs. Laravel Herd
- Create your first project, ShopMetrics
- An Analysis of the Laravel Directory Structure
2. A True Story of an Entrepreneur
(1) Pain Point: Manually maintaining e-commerce analytics scripts
Bob is an independent developer who manually maintains more than 20 PHP analytics scripts for five e-commerce clients—every time a client requests a new report, he has to write SQL from scratch, piece together HTML, and handle file uploads. Last month, Alice's store needed to add a subscription billing feature. It took Bob three all-nighters to deliver it, and the code was scattered across 15 folders—even he couldn't figure out where the logic was. Charlie had it even worse: he tried writing an API in native PHP, only to find that all 2,000 lines of code were riddled with SQL injection vulnerabilities.
(2) Laravel's Solution
Laravel uses a set of elegant conventions to encapsulate repetitive tasks—such as routing, databases, authentication, and queues—into ready-to-use tools. Bob simply needs to define his models and routes, and CRUD pages, API endpoints, and user authentication will all be generated automatically.
# Create project in 30 seconds
composer create-project laravel/laravel ShopMetrics
cd ShopMetrics
php artisan serve
# Visit http://localhost:8000 — your app is running!
(3) Revenue
After Bob rewrote ShopMetrics using Laravel, the time required to generate a new data report was reduced from 3 days to 3 hours, and the amount of code was cut by 70%; Alice's subscription feature went live in just 2 days.
3. What Is Laravel?
Laravel is an open-source PHP web framework created by Taylor Otwell in 2011. It follows the MVC architectural pattern and is known for its "elegant syntax" and "developer experience."
graph LR
A[Laravel Framework] --> B[Routing]
A --> C[Eloquent ORM]
A --> D[Blade Templates]
A --> E[Authentication]
A --> F[Queue System]
A --> G[Event Broadcasting]
A --> H[Artisan Console]
(1) Core Design Philosophy
- Convention over configuration: Following conventions means writing less code; override them only when customization is needed.
- Elegant Syntax: Replace verbose procedural code with fluid chained calls
- Full-Stack Solution: A single framework that covers all needs, from routing to deployment
(2) New Features in Laravel 11
| Feature | Description |
|---|---|
| Streamline the directory structure | Remove 9 files, including app/Http/Kernel.php |
| A Lighter-Weight Bootstrap | bootstrap/app.php Configuring Middleware and Exceptions in a Single File |
| Uses SQLite by default | Ready to use right out of the box, no MySQL configuration required |
| Per-Second Rate Limiting | Rate Limiting Accurate to the Second |
| Scout Search Improvements | Support for full-text search and vector search |
4. An Overview of the Laravel Ecosystem
Laravel not only offers a core framework but also a complete set of official tools that cover the entire process from development to deployment.
| Tool | Purpose | Description |
|---|---|---|
| Forge | Server Management | One-click deployment to DigitalOcean/Vultr |
| Vapor | Serverless Deployment | Serverless Solution Based on AWS Lambda |
| Nova | Backend Panel | Official CMS/Admin Panel |
| Sail | Docker Development Environment | Built-in Docker Compose Configuration |
| Herd | Local Development Environment | Native PHP Runtime for macOS/Windows |
| Breeze | Authenticated Scaffolding | Lightweight Login/Registration Template |
| Sanctum | API Authentication | SPA + Token Dual-Mode Authentication |
| Echo | Real-time Broadcasting | WebSocket Event Push Frontend Library |
(1) ▶ Example: Checking the Laravel version and ecosystem tools
# Check Laravel version
php artisan --version
# Output: Laravel Framework 11.x
# Check installed packages via Composer
composer show | grep laravel
# laravel/framework
# laravel/sail
# laravel/sanctum
# laravel/tinker
Output:
# Command executed successfully
5. Setting Up the Environment
(1) PHP 8.2+ and Composer
Laravel 11 requires PHP 8.2 or later. Composer is a package manager for PHP, similar to npm for Node.js.
| Requirements | Minimum Version | Recommended Version |
|---|---|---|
| PHP | 8.2 | 8.3 |
| Composer | 2.0 | 2.8+ |
| Extension: Ctype | ✅ | ✅ |
| Extension: cURL | ✅ | ✅ |
| Extensions: DOM | ✅ | ✅ |
| Extension: MBstring | ✅ | ✅ |
| Extension: OpenSSL | ✅ | ✅ |
| Extension: PDO | ✅ | ✅ |
| Extension: Tokenizer | ✅ | ✅ |
(1) ▶ Example: Install Composer and Verify the Environment
# Install Composer (macOS/Linux)
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
# Verify PHP and Composer versions
php -v
# PHP 8.3.x (cli)
composer -V
# Composer version 2.8.x
Output:
{"status":"ok","data":{}}
(2) Docker Solutions: Laravel Sail vs. Laravel Herd
| Dimension | Laravel Sail | Laravel Herd |
|---|---|---|
| Principles | Docker Containers | Native PHP + Nginx |
| Platform | Win/Mac/Linux | Mac/Windows |
| Performance | Slower (container overhead) | Faster (runs natively) |
| Isolation | Full Isolation | Partial Isolation |
| Suitable for | Unified team environment | Rapid individual development |
| Startup Time | 30-60 s | 5 s |
(2) ▶ Example: Starting a Project Using Laravel Sail
# Create project with Sail
curl -s https://laravel.build/ShopMetrics | bash
cd ShopMetrics
# Start all services (MySQL, Redis, MeiliSearch...)
./vendor/bin/sail up -d
# Run Artisan commands inside Sail
./vendor/bin/sail artisan migrate
Output:
{"status":"ok","data":{}}
(3) ▶ Example: Starting a Project Using Laravel Herd
# After installing Herd from laravelherd.com
# Herd auto-detects projects in ~/Herd or ~/Sites
cd ~/Herd
composer create-project laravel/laravel ShopMetrics
cd ShopMetrics
# Herd auto-provisions .test domain
# Visit: http://ShopMetrics.test
Output:
# Command executed successfully
6. Create a ShopMetrics Project
(1) Creating a Project Using Composer
composer create-project laravel/laravel ShopMetrics
cd ShopMetrics
(2) Analyzing the Directory Structure
ShopMetrics/
├── app/ # Application core code
│ ├── Http/ # Controllers, Middleware, Requests
│ ├── Models/ # Eloquent ORM models
│ └── Providers/ # Service providers
├── bootstrap/ # Framework bootstrap files
├── config/ # Configuration files
├── database/ # Migrations, Seeders, Factories
├── public/ # Web root (index.php)
├── resources/ # Views, assets, language files
├── routes/ # Route definitions
│ ├── web.php # Web routes
│ └── api.php # API routes
├── storage/ # Logs, cache, compiled files
├── tests/ # PHPUnit/Pest tests
└── vendor/ # Composer dependencies
| Table of Contents | Responsibilities | Analogies |
|---|---|---|
app/ |
Business Logic | The Company's Office |
routes/ |
URL Routing | Company Receptionist |
resources/views/ |
Page Template | Company Showroom |
database/ |
Data Structures | The Company's Archives |
config/ |
Configuration Parameters | Company Policies and Procedures |
public/ |
Web Portal | The Company's Gateway |
(1) ▶ Example: Start the development server and access the home page
cd ShopMetrics
# Start the built-in development server
php artisan serve
# Starting Laravel development server: http://127.0.0.1:8000
# Visit http://127.0.0.1:8000 in browser
# You should see the Laravel welcome page
Output:
# Command executed successfully
7. Comprehensive Example: Initializing the ShopMetrics Project
# ============================================
# Comprehensive: Initialize ShopMetrics project
# Covers: create project, configure .env, run migrations, serve
# ============================================
# 1. Create the Laravel project
composer create-project laravel/laravel ShopMetrics
cd ShopMetrics
# 2. Configure environment
cp .env.example .env
php artisan key:generate
# Application key set successfully.
# 3. Configure database in .env (using SQLite for quick start)
# DB_CONNECTION=sqlite
# DB_DATABASE=database/database.sqlite
# 4. Run default migrations
php artisan migrate
# Created migration tables: users, password_reset_tokens, etc.
# 5. Start development server
php artisan serve
# Server running on http://127.0.0.1:8000
# 6. Verify installation
php artisan about
# Environment: Local
# Laravel Version: 11.x
# PHP Version: 8.3.x
Output:
Application key set successfully.
Info: Using SQLite database: database/database.sqlite
Migration table created successfully.
Running migrations:
0001_01_01_000000_create_users_table ... done
0001_01_01_000001_create_password_reset_tokens_table ... done
Starting Laravel development server: http://127.0.0.1:8000
❓ FAQ
php artisan serve.bootstrap/app.php configuration.vendor/ directory), while npm is the package manager for Node.js (manages the node_modules/ directory). Laravel uses both: Composer manages PHP dependencies, and npm manages front-end resources.php artisan about in the project directory. It will list all environment information, such as the PHP version, extensions, and database drivers; any items that do not meet the requirements will be highlighted in red.📖 Summary
- Laravel is the most popular full-stack framework for PHP, known for its elegant syntax and developer experience
- Laravel 11 has simplified its directory structure and uses SQLite by default, making it easier to get started.
- The Laravel ecosystem includes a complete toolchain such as Forge, Vapor, Sail, Herd, and Sanctum
- For setting up the environment, we recommend using Docker (Sail) or the native installation (Herd); both require PHP 8.2+ and Composer.
- The project directory structure follows the MVC pattern: app/ contains the logic, routes/ contains the routes, and resources/ contains the views
php artisan serveAllows you to quickly start a development server
📝 Exercises
-
Basic Exercise (⭐): Install PHP 8.2+ and Composer locally, and use
composer create-projectto create a Laravel project named ShopMetrics. Make sure you can view the welcome page in your browser. -
Advanced Exercise (⭐⭐): Create the same project using either Laravel Sail or Docker, compare the differences between the
php artisan serveand Sail startup methods, and record the startup time and memory usage. -
Challenge (⭐⭐⭐): Review the changes to the Laravel 11 directory structure (compared to Laravel 10), and list the files that have been removed along with how their functionality is now implemented in Laravel 11.



