This is a simple script along with some useful information to help when setting up a Laravel Sail project that was cloned from source control. I made this because I could not find anywhere that explained how to do this and kept running into problems. The main issue was a problem with database authentication. It turns out that when the Docker volume is created for the database for the first time the password that is in the .env file is used, which I usually created after starting Sail for the first time. Another issue was not having access to the Sail binary to start the containers. This is solved by the script by installing the composer dependencies with a disposable container. If you follow the steps below in order you should not run into any issues. Feel free to leave a comment on this Gist if it could be improved.
- Run the script from the root directory of the Laravel project
curl -s "https://gist.githubusercontent.com/LaurenceRawlings/3b4f801cafb2e683f45a3b573dad868d/raw/15c952586e75d514b909aec6a6e47088563c6612/sail-setup" | bash
- This script can be found at the bottom of the page
- Configure a bash alias
alias sail='[ -f sail ] && bash sail || bash vendor/bin/sail'
- Add a .env file See below for default Sail values
cp .env.example .env
- Start Sail
sail up -d
- Generate app key
sail artisan key:generate
sail atrisan optimize
- Migrate database
sail artisan migrate
Illuminate\Database\QueryException
SQLSTATE[08006] [7] FATAL: password authentication failed for user "sail" (SQL: select * from information_schema.tables where table_schema = public and table_name = migrations and table_type = 'BASE TABLE')
This happens when Sail was started for the first time and the env variables for the database were not set correctly Make sure to update env variables before starting Sail to avoid database authentication issues.
If you get this issue when migrating your database try the following:
- Stop Sail
sail down
- Remove existing database Docker volume
docker volume ls
docker volume rm example-app_sailmysql
- Make sure your databse env variables are all set correctly (see below)
- Sail uses the database credentials in your env file when creating the Docker volume for the frist time
- Restart Sail
sail up -d
sail artisan storage:link
sail npm install
Replace the relevant env variable for the tools you are using in your stack
DB_USERNAME=sail
DB_PASSWORD=password
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_CONNECTION=pgsql
DB_PORT=5432
DB_HOST=pgsql
DB_HOST=mariadb
MEMCACHED_HOST=memcached
REDIS_HOST=redis
SCOUT_DRIVER=meilisearch
MEILISEARCH_HOST=http://meilisearch:7700