開発環境構築とプロジェクト作成(Windows)
WSLの設定(PowerShell)
wsl --install
Windows Terminalのインストール
https://www.microsoft.com/ja-jp/p/windows-terminal/9n0dx20hk701(Microsoft Store)
Docker Desktopのインストール
Get Started
Get started with Docker Desktop and join millions of developers in faster, more secure app development using containers and beyond.
ssh設定
ssh keyを生成
ssh-keygen -t rsa -f 〜/.ssh/afbitbucket_rsa
権限変更
chmod 600 id_rsa 〜/.ssh/afbitbucket_rsa
公開鍵をコピー
pbcopy < ~/.ssh/github_rsa.pub
開発環境構築
プロジェクトをクローン(Windows Terminal(Ubuntu)or terminal)
git clone git@bitbucket.org:TomohitoHorikoshi/aftabletennis.git
docker-compose.yml(clone時に入るので設定不要)
# For more information: https://laravel.com/docs/sail version: '3' services: laravel.test: build: context: ./vendor/laravel/sail/runtimes/8.1 dockerfile: Dockerfile args: WWWGROUP: '${WWWGROUP}' image: sail-8.1/app extra_hosts: - 'host.docker.internal:host-gateway' ports: - '${APP_PORT:-80}:80' environment: WWWUSER: '${WWWUSER}' LARAVEL_SAIL: 1 XDEBUG_MODE: '${SAIL_XDEBUG_MODE:-off}' XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}' volumes: - '.:/var/www/html' networks: - sail depends_on: - mysql 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 volumes: - 'sail-mysql:/var/lib/mysql' networks: - sail healthcheck: test: ["CMD", "mysqladmin", "ping", "-p${DB_PASSWORD}"] retries: 3 timeout: 5s mailhog: image: 'mailhog/mailhog:latest' ports: - '${FORWARD_MAILHOG_PORT:-1025}:1025' - '${FORWARD_MAILHOG_DASHBOARD_PORT:-8025}:8025' networks: - sail phpmyadmin: image: phpmyadmin/phpmyadmin depends_on: - mysql ports: - 8888:80 environment: PMA_USER: '${DB_USERNAME}' PMA_PASSWORD: '${DB_PASSWORD}' PMA_HOST: mysql networks: - sail networks: sail: driver: bridge volumes: sail-mysql: driver: local
composerパッケージ等インストール
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
開発環境構築と起動コマンド
./vendor/bin/sail up -d
開発環境の停止コマンド
./vendor/bin/sail down
.envファイル作成(.env.exampleをコピーして、mysql)
APP_NAME=Laravel
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost
LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=aftabletennis
DB_USERNAME=aftabletennis
DB_PASSWORD=aftabletennis
BROADCAST_DRIVER=log
CACHE_DRIVER=file
FILESYSTEM_DISK=local
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120
MEMCACHED_HOST=memcached
REDIS_HOST=redis
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_MAILER=smtp
MAIL_HOST=mailhog
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="hello@example.com"
MAIL_FROM_NAME="${APP_NAME}"
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
application key生成
sail artisan key:generate
mysqlコンテナ内でユーザー作成
CREATE USER 'aftabletennis'@'localhost' IDENTIFIED BY 'aftabletennis';
権限付与
GRANT ALL ON aftabletennis.* TO 'aftabletennis'@'localhost';
プロジェクトURL
403 Error - Forbidden
エイリアスの登録
① 使用しているシェルの確認
echo $SHELL
②-A エイリアスの登録(/bin/zsh
と表示された場合)
echo "alias sail='[ -f sail ] && bash sail || bash vendor/bin/sail'" >> ~/.zshrc
②-B エイリアスの登録(/bin/bash
と表示された場合)
echo "alias sail='[ -f sail ] && bash sail || bash vendor/bin/sail'" >> ~/.bashrc
③設定反映
exec $SHELL -l
④確認
sail artisan -V
コメント