Introduction
Laravel is one of the most popular PHP frameworks today, known for its elegant syntax, ease of use and powerful tools such as laravel sail. You can read more about the popularity of laravel in a blog post I wrote here.
While setting up a development environment for Laravel used to involve managing multiple dependencies and configurations, Laravel Sail has emerged as a lightweight, easy-to-use command-line interface that provides a pre-configured Docker environment for Laravel.
In this article, we’ll take a closer look at Laravel Sail, what it offers, and how you can quickly get started with it. Whether you’re new to Docker or Laravel, this guide will help you set up a development environment that’s both efficient and robust.
The example set up covered here will be for Mac OS using Laravel 11, for windows and linux installations please consult the laravel sail documentation, a link can be found at the bottom of this article.
If you don’t have a Laravel installation considering viewing this post as it show you how to create a new application with Laravel Sail already installed.
What is Laravel Sail?
Laravel Sail is an official development environment for Laravel, built on top of Docker. It allows developers to quickly get up and running with a containerized development setup, without needing to manually configure Docker images or services. By providing an out-of-the-box solution, Sail simplifies the often complex task of managing dependencies like MySQL, Redis, and PHP versions.
Key Benefits of Laravel Sail:
- Simplicity: You don’t need to install PHP, MySQL, or other services locally. Sail handles everything through Docker.
- Consistency: By using Docker containers, you ensure that your development environment matches your production setup, reducing bugs due to configuration discrepancies.
- Customization: You can easily tweak Sail’s configuration to meet the specific needs of your application, such as adding Redis or changing the PHP version.
Prerequisites for Using Laravel Sail
Before diving into Laravel Sail, make sure you have the following installed:
- Docker and Docker Compose: These are required for running the containerized environment. If you haven’t installed Docker yet, head to Docker’s official site and follow the setup instructions for your OS.
- Composer: Laravel Sail is a Composer package, so make sure Composer is installed on your system.
- An existing Laravel app. If you don’t have one we will use composer to install one. Or view this post on how to create a new Laravel app with Laravel Sail already installed.
It’s also recommended to have some basic understanding of PHP and Docker, although Sail simplifies much of the configuration for you.
Setting Up Laravel Sail
Let’s walk through setting up a new Laravel project using Laravel Sail.
Step 1: Install Laravel via Composer
If you don’t have an existing laravel app, first create a new Laravel project using composer. In your terminal run the following command:
composer create-project laravel/laravel example-app
Replace example-app with your project name.
Navigate into your new project using the following command:
cd example-app
Step 2: Install Laravel Sail
Next, add Sail to your project as a development dependency:
composer require laravel/sail --dev
Step 3: Publish the Sail docker files
After installing Sail, publish its Docker configuration files by running:
php artisan sail:install
This command will generate a docker-compose.yml file that defines the services your app will use, such as PHP, MySQL, and Redis.
Step 4 Start Laravel Sail:
Now, you’re ready to start the development environment. Run the following command to launch Sail:
./vendor/bin/sail up
When the containers have started you can now access your project using the following link: http://localhost you should seen a screen like this:
Step 5 Add Additional Services:
If you need to add any other sail services you can use this command:
php artisan sail:add
You will be presented with a list of options in the terminal. Navigate through the list using the arrow keys and use the space bar to select the services you want.

After your new services have been installed, run the following commands:
./vendor/bin/sail build --no-cache
This will rebuild your Docker environment with the new services included.
You can also switch PHP versions depending on your development needs.
Common Sail Commands
Here are some of the most common commands you’ll use while working with Laravel Sail:
Starting and Stopping Sail
./vendor/bin/sail up
./vendor/bin/sail down
up launches your environment, while down stops the Docker containers.
Running Artisan, Composer, or NPM Commands
Laravel Sail provides easy access to common Laravel commands like Artisan, Composer, and NPM:
./vendor/bin/sail artisan migrate
./vendor/bin/sail composer install
./vendor/bin/sail npm run dev
This allows you to run Laravel commands without needing to directly access the Docker containers.
Viewing Logs and Troubleshooting
You can also view logs for your application and services by using Docker’s logging feature:
docker-compose logs
This will display logs from all the containers, which can be useful for debugging.
Using Sail In Development
Once Sail is up and running, you can use it just like any other development environment. Some common use cases include:
- Developing New Features: Since Sail provides all necessary services (database, caching, etc.), you can easily develop and test features without worrying about local environment issues.
- Team Collaboration: Sail ensures that everyone on your team has the same development environment, reducing the “works on my machine” problem.
If performance becomes a concern, especially on slower machines, consider configuring Docker to use more resources or limiting the number of services running at once.
Deploying after using Sail
It’s important to note that Laravel Sail is designed for local development and not for production environments. When you’re ready to deploy, you’ll need to move away from Sail and deploy your app using other tools, such as Laravel Forge, Docker Compose, or managed platforms like AWS or DigitalOcean.
For small projects, you might even use Docker Compose in production, but for most production environments, it’s better to use a dedicated deployment solution.
Troubleshooting and Common Issues
While Sail is easy to use, there are some common issues you might encounter:
- Docker Not Running: Make sure Docker is installed and running on your system.
- Port Conflicts: If you have other services running on the default ports (e.g., MySQL), you might need to adjust the port numbers in the docker-compose.yml file.
- Performance Issues: Docker can be resource-intensive, especially on machines with limited memory. Consider adjusting the resource limits in Docker’s settings.
If you run into any issues, check the Sail official documentation or reach out to the community for support.
Conclusion
Laravel Sail makes it incredibly easy to set up a local development environment for Laravel using Docker. It’s perfect for developers who want a consistent, containerized setup without the hassle of manual configuration. With its simple commands and flexibility, Sail can save you hours of setup time and help you avoid environment-related bugs.
Now that you know how to get started with Sail, give it a try in your next Laravel project and experience the power of Docker-based development!
Additional Resources
Looking for a Laravel Developer? Contact Me to Discuss Your Project!
I’d be interested in hearing from you if you need a web developer to work on your upcoming project. Whether you require a front-end developer to create a stunning user interface, a back-end developer to build server-side logic, or a full-stack developer to handle everything from start to finish, I have the knowledge and experience needed to produce excellent results. Therefore, don’t be afraid to email me at contact@dalehudson.co.uk if you’re interested in working together or have any questions about my services. I would be delighted to talk with you about potential projects and assist you in realising your visions.