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.
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:
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:
Accessing the Database
- Host: 127.0.0.1
- Port: 3306
- Username/Password: from your
.env
file
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:
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
sail artisan migrate
→ Run Laravel migrations
sail composer install
→ Install Composer dependencies
sail npm run dev
→ Build frontend assets
sail tinker
→ Open Laravel Tinker shell
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.