Copied!
Laravel

Laravel Sail Setup Guide with MySQL & Redis (Beginner-Friendly Docker Tutorial)

laravel-sail-setup-guide
Shahroz Javed
Oct 15, 2025 . 28 views

Table Of Contents

 

Introduction

Laravel Sail provides a simple, Docker-based local development environment for Laravel applications — no need to manually configure PHP, MySQL, Redis, or Nginx. In this guide, you’ll learn how to set up Laravel Sail with MySQL and Redis and master the most used Sail commands.

💡 Related: Check our guide on Docker Setup for Windows (WSL2) if Docker isn’t configured yet.

Installing Laravel Sail

First, make sure your Laravel application is already created. Then install Sail as a development dependency using Composer:

composer require laravel/sail --dev

Once installed, publish the Sail configuration for your app:

php artisan sail:install

When prompted, select the services you want — for this setup, choose MySQL and Redis.

⚠️ Note: This command creates a docker-compose.yml file that defines containers for PHP, MySQL, Redis, and more.

Running Sail Commands

To start the Sail environment, open your Ubuntu (WSL2) terminal and navigate to your project folder.

cd /mnt/e/practice/laravel/laravel-sail
./vendor/bin/sail up

Once containers are up, access your Laravel app in the browser:

http://localhost/

Accessing the Database

Docker Context

If Docker is not pointing to the correct context, reset it:

docker context use default

Adding Additional Services

You can add more services like Meilisearch, MailHog, or Selenium anytime:

php artisan sail:add

Laravel Sail will automatically update your docker-compose.yml with the new service configurations.

Rebuilding Sail Images

If you’ve made changes to your Dockerfile or added new dependencies, rebuild your containers:

docker compose down -v
sail build --no-cache
sail up
⚠️ Tip: Always use --no-cache when rebuilding to ensure all layers are freshly built.

Configuring a Shell Alias

Running ./vendor/bin/sail repeatedly can be annoying. Create an alias to shorten it:

alias sail='sh $([ -f sail ] && echo sail || echo vendor/bin/sail)'

Now you can use sail directly instead of typing the full path.

Starting and Stopping Sail

Here are the most commonly used commands to control Sail containers:

# Start Sail (interactive)
sail up

# Start Sail in detached mode
sail up -d

# Stop all containers
sail stop

# Shut down and remove containers
sail down

Useful Sail Commands

Conclusion

Laravel Sail makes it easy to run a fully containerized Laravel app without needing to install PHP, MySQL, or Redis manually. With just a few commands, you get a consistent development environment that mirrors production closely.

13 Shares

Similar Posts