5
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Laradockを使用して Laravel の開発環境構築

Last updated at Posted at 2020-02-05

ディレクトリの作成

mkdir myapp
cd myapp

Laradockの導入

git clone https://github.com/Laradock/laradock.git [名前を指定したい場合は入力]

Laradockの.envを編集

cd laradock
cp env-example .env

.envを開いて以下の通りに編集する

APP_CODE_PATH_HOST=../APP_CODE_PATH_HOST=../src/ に変更し、保存します。

Dockerコンテナの起動 & ビルド

docker-compose up -d nginx mysql
// ワークスペースに入る
docker-compose exec workspace bash

Laravelのコマンドはworkspace内で実行できる

Laravelのインストール

composer create-project --prefer-dist laravel/laravel ./

src/.env (変更後)

DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=default
DB_USERNAME=default
DB_PASSWORD=secret

ここでphp artisan migrateしてみる

root@c137d5c70b48:/var/www# php artisan migrate

   Illuminate\Database\QueryException  : SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = default and table_name = migrations and table_type = 'BASE TABLE')

このままだとエラーが発生する
原因:MySQLコンテナに入ってMySQLにログインしてuserの認証方式を変更する必要がある。

別タブで
docker-compose exec mysql bash
を実行してMySQLコンテナに入る。

mysql -u root -p

パスワードはroot

以下のコマンドで認証方式を変更

mysql> ALTER USER 'default'@'%' IDENTIFIED WITH mysql_native_password BY 'secret';
mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'secret';

workspaceコンテナで
php artisan migrate

5
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?