Setting Up Your Laravel 12 Development Environment
A proper development environment is the foundation of productive Laravel development. Let us set everything up correctly from the start.
Requirements
- PHP 8.2+ with extensions: BCMath, Ctype, cURL, DOM, Fileinfo, JSON, Mbstring, OpenSSL, PDO, Tokenizer, XML
- Composer 2.x — PHP dependency manager
- Node.js 18+ — For frontend asset compilation
- MySQL 8.0+ or PostgreSQL 15+
Installing Laravel 12
The recommended way to create a new Laravel 12 project:
composer create-project laravel/laravel my-app
cd my-app
php artisan serve
Or using the Laravel installer:
composer global require laravel/installer
laravel new my-app
The installer will ask you to choose a starter kit (React, Vue, Livewire, or none) and a testing framework (PHPUnit or Pest).
Using Laravel Herd (Recommended)
Laravel Herd provides a zero-configuration development environment for macOS and Windows:
# After installing Herd, simply place your project in the Herd directory
# Your app is instantly available at http://my-app.test
Environment Configuration
Laravel uses .env files for environment-specific configuration:
APP_NAME="My Application"
APP_ENV=local
APP_DEBUG=true
APP_URL=http://my-app.test
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_DATABASE=my_app
DB_USERNAME=root
DB_PASSWORD=
Important: Never use env() directly in your application code. Always use config() helper which reads from cached configuration files:
// Bad
$name = env('APP_NAME');
// Good
$name = config('app.name');
Directory Structure
Key directories in a Laravel 12 application:
app/Models/— Eloquent modelsapp/Http/Controllers/— Request handlersroutes/web.php— Web routesresources/views/— Blade templatesdatabase/migrations/— Database schematests/— PHPUnit test files