Sail
Environment Sail
Categories:
Install
If your laravel version is NOT >= 8.x
, then the sail
will not install in your project by default. So you have to install the sail by yourself.
composer require laravel/sail --dev
Initialize laravel sail
php artisan sail:install
Alias your sail command
We have to run the sail command from the vendor
folder everytime. For our convenient, we can alias the sail command to the ~/.bashrc
or ~/.zshrc
file. Then we can simply use the short version sail command to run the code.
alias sail="./vendor/bin/sail"
Command
Command | Description |
---|---|
sail up -d | Run the sail on the background |
sail stop | Stop the sail |
sail down | Stop the sail and delete all docker container |
sail build –no-cache | Rebuild the whole sail container and ignore docker image cache |
sail php –version | Show the php version |
sail composer install | Run the composer command |
sail artisan queue:work | Run the laravel artisan command |
sail shell custom-shell.sh | Run the custom shell command |
Database privilege
MySQL
Name | Value |
---|---|
username | sail |
password | password |
root username | root |
root password | password |
Hostname | 127.0.0.1:3306 |
Change Sail MySQL Username And Password
A. Bring the sail down
sail down -v
B. Change MySQL password
B.1 Change .env
file (Better way)
Edit the .env
file to change your password.
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=example_app
DB_USERNAME=sail_custom_username
DB_PASSWORD=password_custom_password
B.2 Directly change the docker-compose.yml
file to fixed
username and password (Worse way)
Edit the docker-compose.yml
file, then enter your personal username and password
- MYSQL_USER:
'${DB_USERNAME}'
- MYSQL_PASSWORD:
'${DB_PASSWORD}'
version: '3'
services:
mysql:
image: 'mysql/mysql-server:8.0'
ports:
- '${FORWARD_DB_PORT:-3306}:3306'
environment:
MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
MYSQL_ROOT_HOST: "%"
MYSQL_DATABASE: '${DB_DATABASE}'
MYSQL_USER: '${DB_USERNAME}'
MYSQL_PASSWORD: '${DB_PASSWORD}'
MYSQL_ALLOW_EMPTY_PASSWORD: 1
C. Remove cache and re-build
sail build --no-cache
D. Bring the sail up
sail up -d