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:
- Download the installer: herd.laravel.com
- Run
Herd Installer.exe
→ Next → Install - 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:
- Click on the Herd icon in the system tray.
- Make sure that the Nginx and PHP services are active (green indicators).
- In your projects folder (e.g., C:\Users\YourUser\Code), create a
test
folder, and inside it, anindex.php
file with the content<?php phpinfo(); ?>
. - In Herd, via the
sites
tab, specify the path to thetest
folder and click "Add site". - 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):
4. Installing PHP and Composer
If you are not using Herd:
- PHP:
- Download PHP 8.3 for Windows
- Unpack to
C:\PHP
- Add to PATH:
- Composer:
- Run Composer-Setup.exe
- Check:
5. Installing PostgreSQL
For working with databases:
- Download PostgreSQL 15
- Run the installer:
- Password for the superuser:
admin
(or your own) - Port:
5432
(standard) - After installation:
- 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
- Create a database for the project:
space_api
6. Installing Laravel
-
Via Composer:
-
Initialize Git (optional):
-
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):
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 configurationcomposer.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
🚀 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 athttp://localhost:8000
.- In any case, check that the created
space_api
database is visible inpgAdmin 4
.