Skip to main content

Installation and Environment Setup

2/28
Chapter 1 Getting Started with Laravel 12

Installation and Environment Setup

20 min read Lesson 2 / 28

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).

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 models
  • app/Http/Controllers/ — Request handlers
  • routes/web.php — Web routes
  • resources/views/ — Blade templates
  • database/migrations/ — Database schema
  • tests/ — PHPUnit test files