Laravel Sail
Sign in

Topics

Backend

Tools & DevOps

All guides

Search

Topics

Practice

Tools · Laravel Sail

Laravel Sail: The Ultimate Local-Stack Guide

Author: Volodymyr Pichkurov Published: 4 min read
Laravel Laravel Sail Docker

Laravel Sail is a beautiful Docker Compose wrapper designed to stand up a complete development environment (PHP-FPM, MySQL, Redis, Meilisearch, Mailpit, etc.) without managing server configurations on your host machine.

However, Sail is not a production environment. Understanding the boundary between local Sail and real-world production deployment is key to avoiding the dreaded "works on my machine" syndrome. Let's master Sail together!


Mental Model & Prerequisites

Sail does not install PHP or Node on your host machine. Instead, it runs commands inside containerized runtimes.

If you are on Windows, you MUST run Docker inside WSL2 (Windows Subsystem for Linux) and keep your project folder inside the Linux filesystem (e.g., ~/Development/my-app), not the Windows C:\ partition. Working across the Windows-Linux mount boundary causes extreme disk I/O bottlenecks.


Essential CLI Shortcuts

Tired of typing ./vendor/bin/sail every time? Add a shell alias!

bash
# ~/.zshrc or ~/.bashrc
alias sail='[ -f sail ] && sh sail || sh vendor/bin/sail'

Now you can run daily commands efficiently:

  • sail up -d — Start all services in the background.
  • sail down — Stop services.
  • sail artisan migrate — Run database migrations.
  • sail npm run dev — Run Vite assets locally.

Changing PHP Versions

To upgrade or downgrade your PHP version in Sail, you must modify your Compose config.

docker-compose.yml
services:
    laravel.test:
        build:
            context: ./vendor/laravel/sail/runtimes/8.4
            dockerfile: Dockerfile
            args:
                WWWGROUP: '${WWWGROUP}'
                # Change this build argument to the desired minor version:
                PHP_VERSION: '8.4'

After modifying the file, rebuild the container layers without cache:

bash
# Terminal
sail build --no-cache
sail up -d

Customizing Services

1. Connecting to Redis

If you skipped Redis during installation, you can add it by editing your Compose configuration:

docker-compose.yml
services:
    redis:
        image: 'redis:alpine'
        ports:
            - '${FORWARD_REDIS_PORT:-6379}:6379'
        volumes:
            - 'sail-redis:/data'
        networks:
            - sail

Make sure your environment file matches this:

.env
REDIS_HOST=redis
REDIS_PORT=6379

Note

Did you know? Inside the Sail network, containers communicate with each other using their service names (like redis or mysql) as hostnames. Using 127.0.0.1 will fail because it points to the application container itself!

2. Switching from MySQL to PostgreSQL

To swap database engines, replace the mysql block with pgsql in your docker-compose.yml:

docker-compose.yml
services:
    pgsql:
        image: 'postgres:15-alpine'
        ports:
            - '${FORWARD_DB_PORT:-5432}:5432'
        environment:
            POSTGRES_DB: '${DB_DATABASE}'
            POSTGRES_USER: '${DB_USERNAME}'
            POSTGRES_PASSWORD: '${DB_PASSWORD}'
        volumes:
            - 'sail-pgsql:/var/lib/postgresql/data'
        networks:
            - sail

And update your .env:

.env
DB_CONNECTION=pgsql
DB_HOST=pgsql
DB_PORT=5432

Debugging with Mailpit & Xdebug

Mailpit (Fake Mail Server)

Sail automatically routes outgoing mail to Mailpit. It intercepts emails so you don't accidentally send test messages to real customers. Configure SMTP in .env:

.env
MAIL_MAILER=smtp
MAIL_HOST=mailpit
MAIL_PORT=1025

You can view the intercepted emails by opening the web UI at http://localhost:8025.

Xdebug

To enable step-by-step debugging, simply set the Xdebug mode in your environment:

.env
SAIL_XDEBUG_MODE=develop,debug

Restart Sail (sail down && sail up -d) to apply the configuration.


Sail (Local) vs. Production Comparison

Feature Laravel Sail (Local Dev) Production Environment
HTTP Server PHP built-in server Nginx / Apache + PHP-FPM, or Octane
Queues Run via terminal sail artisan queue:work Managed via Supervisor or Systemd
SSL / HTTPS Plain HTTP on localhost TLS terminated on Nginx, Cloudflare or Load Balancer
Cache & Sessions File storage or local Redis container Clustered Redis or Managed Memcached
Database Ephemeral container Managed DB (RDS, Cloud SQL) with backups

⚠️ Common Mistakes

1. Connecting to 127.0.0.1 for Redis/Database inside Sail If your DB_HOST is set to 127.0.0.1 in .env, your app will not be able to find the database container. Use the service name (mysql or pgsql) instead.

2. Running commands on the host instead of the container Running composer install or php artisan migrate on your local terminal can lead to version mismatches or missing PHP extension errors. Always run them through Sail:

bash
# Terminal
sail composer install
sail artisan migrate

🧠 Self-Check Questions

  1. Why is it important to use WSL2 filesystem paths (like ~/Development) instead of mounting directly from Windows partitions (/mnt/c/...)?
  2. True or False? To enable PostgreSQL, you must manually download and compile the pdo_pgsql driver inside the Sail container.
  3. What hostname should you use in .env to send emails via Mailpit inside Sail?
  4. How do you restart a queue worker in Sail so that it loads updated code changes?
Reveal Answers
  1. Mounting from Windows drives (C:\) onto a Linux Docker container introduces severe translation and virtualization layers, slowing down file operations and asset compilation (Vite/Mix) up to 10x.
  2. False. Sail's pre-built PHP runtimes already bundle standard extensions, including pdo_pgsql. You only need to switch the service in docker-compose.yml and .env.
  3. You must use mailpit as the host.
  4. Run sail artisan queue:restart, or run the worker with --max-jobs=1 during development.

Was this guide helpful?

Read next

// Newsletter

New Tools guides by e-mail

One e-mail a week with new guides on Tools. No spam, unsubscribe in one click.

// Practise this topic

Tools

About the author

Volodymyr Pichkurov View portfolio

Spotted a mistake? Suggest an edit

Help us improve this article. Suggest edits, additions, or corrections.

No suggestions submitted yet. Be the first to share your feedback!

On this page