Skip to content

Chapter 2.1: Preparing the Laravel Environment

Study time: 1-2 hours

1. Why do you need a local environment?

Imagine you are building a space probe. Before launching it into space, you test all systems on Earth. A local environment is your "control laboratory" for code:

  • Safe experiments without affecting the production server
  • Fast deployment of dependencies
  • Easy switching between software versions

💡 Space analogy: Herd = Mobile launch complex Docker = Space station simulator XAMPP = Stationary test stand


2. Installing Herd

Herd is a modern tool for managing a PHP environment (similar to Laravel Valet).

Installation steps:

  1. Download the installer: herd.laravel.com
  2. Run Herd Installer.exe → Next → Install
  3. After installation:
    • Open Herd from the Start menu. The application icon will appear in the system tray (next to the clock).
    • Click on the Herd icon: make sure that Nginx and the required version of PHP (e.g., 8.3) are running (marked with a green dot).
    • Go to Herd Paths and add the folder where your projects will be stored (e.g., C:\Users\YourUser\Code). Herd will automatically create a nice domain like folder-name.test for each subdirectory in this folder.

⚠️ Important! During installation: - Allow network access (if requested by the firewall) - Check the path in PATH: C:\Program Files\Herd\bin

Checking the work:

  1. Click on the Herd icon in the system tray.
  2. Make sure that the Nginx and PHP services are active (green indicators).
  3. In your projects folder (e.g., C:\Users\YourUser\Code), create a test folder, and inside it, an index.php file with the content <?php phpinfo(); ?>.
  4. In Herd, via the sites tab, specify the path to the test folder and click "Add site".
  5. Open http://test.test in your browser. You should see a page with PHP information.

3. Alternative methods (briefly)

Tool For whom Pros Cons
Laravel Sail (Docker) For all levels Complete isolation, environment reproducibility, official Laravel support Requires Docker installation, consumes more resources
XAMPP Beginners All-in-One installer Cumbersome, harder to manage software versions, clutters the system
Laragon Windows developers Fast, easy to switch versions, automatic host configuration Requires manual web server restart when adding a new project

Example with Docker (Laravel Sail):

# After installing Docker
./vendor/bin/sail up


4. Installing PHP and Composer

If you are not using Herd:

  1. PHP:
    • Download PHP 8.3 for Windows
    • Unpack to C:\PHP
    • Add to PATH:
      # It is recommended to run in PowerShell as an administrator
      [Environment]::SetEnvironmentVariable("Path", "$env:Path;C:\PHP", "User")
      
  2. Composer:

5. Installing PostgreSQL

For working with databases:

  1. Download PostgreSQL 15
  2. Run the installer:
  3. Password for the superuser: admin (or your own)
  4. Port: 5432 (standard)
  5. After installation:
  6. Open pgAdmin 4 (graphical client)

    You can use any other client to work with the database, for example, DBeaver, DataGrip, or even the command line. I prefer DBeaver - but it's a matter of taste

  7. Create a database for the project: space_api

6. Installing Laravel

  1. Via Composer:

    composer create-project laravel/laravel space-api
    cd space-api
    

  2. Initialize Git (optional):

    git init
    git add .
    git commit -m "Start of the space project"
    

  3. Starting and checking the server:

    If you are using Herd: Make sure your space-api project is in the folder you added to Herd. Open in your browser: http://space-api.test You should see the Laravel start page. The server is already running thanks to Herd!

If you are NOT using Herd (manual installation):

php artisan serve
Open in your browser: http://localhost:8000 → The Laravel start page should appear!

When creating a project in Herd:

Just follow the on-screen instructions. For convenience, the project name will be space-api. Any starter kit will do, but I prefer React.

Be sure to turn on phpunit - we will need it later

7. Project setup

Important files:

  • .env — environment settings (keys, databases)
  • config/database.php — DBMS configuration
  • composer.json — PHP dependencies

Connecting the database to the project:

Add to .env:

DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=space_api
DB_USERNAME=postgres # Login for postgres
DB_PASSWORD=admin # Password for postgres

First Artisan commands:

php artisan key:generate  # Generate application key
php artisan migrate:fresh # Database migration (When switching to postgres)


Quiz to consolidate

1. Herd is...

2. What tool does Laravel use to manage PHP dependencies?

3. The standard port for PostgreSQL is:

4. The command to create a Laravel project via Composer is:

5. The file with environment settings is?


🚀 Chapter summary

You have deployed a "launch pad" for the space API! Now you have:

  • 🛠️ A local environment (Herd or manual installation) with PHP and Nginx
  • 🐘 An installed PostgreSQL database server
  • 🚀 A space-api Laravel project
  • 🔌 A configured database connection

📌 Check:

  • If you are using Herd: Make sure the site opens at http://space-api.test.
  • If you are not using Herd: Make sure the php artisan serve command works and the site opens at http://localhost:8000.
  • In any case, check that the created space_api database is visible in pgAdmin 4.