Laravel Tutorial · Laravel Basics · Lesson 2 of 27
Laravel Get Started
Install Laravel, create a project, and learn the folder structure and the commands you'll use every day.
Create a project
You need PHP 8.3+ and Composer (PHP's package manager). Then:
composer create-project laravel/laravel blog
cd blog
php artisan serve # http://127.0.0.1:8000
Or install the Laravel installer once (composer global require laravel/installer) and run laravel new blog, which offers starter kits (React, Vue, Livewire) with authentication ready.
The folder structure
| Folder / file | What goes there |
|---|---|
app/Http/Controllers |
Controllers that handle requests |
app/Models |
Eloquent models (one per table) |
routes/web.php, routes/api.php |
Route definitions |
resources/views |
Blade templates |
database/migrations, seeders, factories |
Schema changes and test data |
config/ |
Configuration files (read values with config('app.name')) |
.env |
Secrets and environment-specific settings (never committed) |
tests/ |
Feature and unit tests |
bootstrap/app.php |
Application setup: routing files, middleware, exception handling |
Artisan
php artisan lists every command. You'll use these constantly:
php artisan make:model Post -mfc # model + migration + factory + controller
php artisan migrate # run migrations
php artisan route:list # show all routes
php artisan tinker # an interactive shell inside your app
php artisan test # run the test suite
Configuration and environment
Settings come from config/*.php, which read .env values with env(). In your code, always use config('...'), never env() directly, so configuration caching works in production.
<?php
echo 'Laravel version: ', app()->version(), "\n";
echo 'Environment: ', app()->environment(), "\n";
echo 'Timezone: ', config('app.timezone'), "\n";
echo 'Default cache store: ', config('cache.default'), "\n";
echo 'Is this the production environment? ', app()->isProduction() ? 'yes' : 'no', "\n";
Output
Laravel version: 13.38.0 Environment: local Timezone: UTC Default cache store: array Is this the production environment? no
Run this on your computer — see “Get Started” for setup.
Test yourself
Where should secrets like database passwords live in a Laravel project?
config/app.phpThe .env fileroutes/web.phpapp/Models
Show answer
Answer: The .env file