> ## Content Index
> Fetch the complete content index at: https://michaelbrooks.co.uk/llms.txt
> Use this file to discover other available public pages before exploring further.

# Add Laravel Sail into your current Laravel project
- URL: https://michaelbrooks.co.uk/add-laravel-sail-into-your-current-laravel-project/
- Published: 2024-10-10T07:19:40.000Z
- Updated: 2024-10-10T07:19:40.000Z
- Author: Michael Brooks
- Tags: docker, laravel, Sail, tutorial, #wordpress

Yesterday Taylor Otwell released a brand new package called Sail which will be available by default in every new Laravel project. However, if you already have your own Laravel project you might want to include it.

Contents

## What is Laravel Sail?

Laravel Sail is a light-weight command-line interface for interacting with Laravel’s default Docker development environment. Sail provides a great starting point for building a Laravel application using PHP, MySQL, and Redis without requiring prior Docker experience.

At its heart, Sail is the `docker-compose.yml` file and the `sail` script that is stored at the root of your project. The `sail` script provides a CLI with convenient methods for interacting with the Docker containers defined by the `docker-compose.yml` file.

Laravel Sail is supported on macOS, Linux, and Windows (via WSL2).

## Update on adding Sail

There is an even easier way to add Sail to an existing Laravel project. Thanks to [Paul Redmond](https://twitter.com/paulredmond?ref=michaelbrooks.co.uk) on Twitter for replying to me.

Require the Sail package with `composer require laravel/sail --dev` then run the install command `php artisan sail:install` and finally publish the env config `php artisan sail:publish`. And now you have Sail set up with your current project.

## Original:

## How to add Laravel Sail into your current project

Firstly, in the root of your project you will want to add a docker-compose.yml file.

```yml
# For more information: https://laravel.com/docs/sailversion: '3'services:    laravel.test:        build:            context: ./vendor/laravel/sail/runtimes/8.0            dockerfile: Dockerfile            args:                WWWGROUP: '${WWWGROUP}'        image: sail-8.0/app        ports:            - '${APP_PORT:-80}:80'        environment:            WWWUSER: '${WWWUSER}'            LARAVEL_SAIL: 1        volumes:            - '.:/var/www/html'        networks:            - sail        depends_on:            - mysql            - redis            # - selenium    # selenium:    #     image: 'selenium/standalone-chrome'    #     volumes:    #         - '/dev/shm:/dev/shm'    #     networks:    #         - sail    #     depends_on:    #         - laravel.test    mysql:        image: 'mysql:8.0'        ports:            - '${DB_PORT}:3306'        environment:            MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'            MYSQL_DATABASE: '${DB_DATABASE}'            MYSQL_USER: '${DB_USERNAME}'            MYSQL_PASSWORD: '${DB_PASSWORD}'            MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'        volumes:            - 'sailmysql:/var/lib/mysql'        networks:            - sail    redis:        image: 'redis:alpine'        ports:            - '${REDIS_PORT}:6379'        volumes:            - 'sailredis:/data'        networks:            - sail    # memcached:    #     image: 'memcached:alpine'    #     ports:    #         - '11211:11211'    #     networks:    #         - sail    mailhog:        image: 'mailhog/mailhog:latest'        ports:            - 1025:1025            - 8025:8025        networks:            - sailnetworks:    sail:        driver: bridgevolumes:    sailmysql:        driver: local    sailredis:        driver: local
```

## Update your .env file

There’s a couple of changes you need to make to your .env file which can be done through a find and replace.

```shell
DB_HOST=mysqlQUEUE_CONNECTION=databaseMEMCACHED_HOST=memcachedREDIS_HOST=redisMAIL_HOST=mailhogMAIL_PORT=1025
```

## Run Composer

Next, run `composer require laravel/sail --dev` to install the Sail package. Once installed you will be able to run `vendor/bin/sail up` to build and run the Sail containers. If you would like to learn more about Sail, then you can read the [Laravel documentation here](https://laravel.com/docs/sail?ref=michaelbrooks.co.uk).