Skip to content

Instantly share code, notes, and snippets.

@Surf-logic
Last active January 20, 2023 02:25
Show Gist options
  • Save Surf-logic/5b32da9a75cd449b335e6bb2807694bd to your computer and use it in GitHub Desktop.
Save Surf-logic/5b32da9a75cd449b335e6bb2807694bd to your computer and use it in GitHub Desktop.
Laravel Sail cheat sheet

Laravel Sail cheet sheet

Install dependencies

Replace php81 with php74, php80, php81, etc.

docker run --rm \
    -u "$(id -u):$(id -g)" \
    -v $(pwd):/var/www/html \
    -w /var/www/html \
    laravelsail/php81-composer:latest \
    composer install --ignore-platform-reqs`

Install Sail

php artisan sail:install

Custom PHP version

Update context: ./vendor/laravel/sail/runtimes/8.0 and image: sail-8.0/app

version: '3'
services:
    engamp8.test:
        build:
            context: ./vendor/laravel/sail/runtimes/8.0
            dockerfile: Dockerfile
            args:
                WWWGROUP: '${WWWGROUP}'
        image: sail-8.0/app

Custom npm version

build:
	context: ./vendor/laravel/sail/runtimes/8.2
	dockerfile: Dockerfile
	args:
		WWWGROUP: '${WWWGROUP}'
		NODE_VERSION: 16

Build and start the Laravel Sail docker container

./vendor/bin/sail up -d

Run test suite

./vendor/bin/sail test

Check node version

sail node --version

Install npm

sail npm install

Execute npm commands

sail npm run dev

AWS S3 environment variables

FILESYSTEM_DISK=s3
AWS_ACCESS_KEY_ID=sail
AWS_SECRET_ACCESS_KEY=password
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=local
AWS_ENDPOINT=http://minio:9000
AWS_USE_PATH_STYLE_ENDPOINT=true
AWS_URL=http://localhost:9000/local

MinIO console

http://localhost:8900

Replace in phpunit.xml

<env name="DB_DATABASE" value="testing"/>

Run tests

sail artisan test

Rebuild container images

sail build --no-cache

Setup Sail alias

alias sail='[ -f sail ] && sh sail || sh vendor/bin/sail'

App service name

If APP_SERVICE different from laravel.test. To match service in docker-compose.yml file.

version: '3'
services:
    serviceName:
        build:
            context: ./vendor/laravel/sail/runtimes/8.0
            dockerfile: Dockerfile
            args:
                WWWGROUP: '${WWWGROUP}'
        image: sail-8.0/app

Add to .env file

APP_SERVICE="serviceName"

Remove old images

This can resolve "SQLSTATE[HY000] [1045] Access denied for user" error

./vendor/bin/sail down --rmi all -v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment