Get Laravel installed and understand how everything fits together before writing a single line of code.
Laravel 10/11 requires the following on your machine:
| Tool | Minimum Version | Check Command |
|---|---|---|
| PHP | 8.2+ | php -v |
| Composer | 2.x | composer --version |
| MySQL / SQLite | 8.0 / any | mysql --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
# 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
# Install the global installer once composer global require laravel/installer # Then create projects faster laravel new blog_app cd blog_app php artisan serve
php artisan serve --port=8080
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
.env, run php artisan config:clear to clear the cached config.php artisan key:generate # Application key set successfully.
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
Artisan is Laravel's command-line tool. Run php artisan list to see all commands.
| Command | What It Does |
|---|---|
php artisan serve | Start local dev server |
php artisan make:controller PostController | Create a controller |
php artisan make:controller PostController --resource | Create resourceful controller |
php artisan make:model Post | Create an Eloquent model |
php artisan make:model Post -m | Model + migration together |
php artisan make:migration create_posts_table | Create a migration file |
php artisan migrate | Run pending migrations |
php artisan migrate:rollback | Undo last migration batch |
php artisan migrate:fresh | Drop all tables and re-migrate |
php artisan db:seed | Run database seeders |
php artisan tinker | Interactive Laravel REPL |
php artisan route:list | Show all registered routes |
php artisan config:cache | Cache configuration files |
php artisan cache:clear | Clear application cache |
php artisan make:middleware CheckAge | Create a middleware class |
php artisan make:request StorePostRequest | Create a form request |
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'
php artisan config:cache in production to merge all config into one cached file for faster boot times.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.
.env changes require config:clear.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>
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
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