gitリポジトリをcloneして、環境構築 - d-sazanami/laravel-jissenkaihatsu-v1 GitHub Wiki

todo

  1. gitリポジトリをclone
  2. 既存アプリケーションでComposer依存関係のインストール
  3. sail up
  4. APP_KEY生成
  5. DB_HOST変更

1.gitリポジトリをclone

Windowsのgitターミナルなどで、 git clonegit init 後に、 git remote add でリポジトリのソースをローカルに持ってくる

2. 既存アプリケーションでComposer依存関係のインストール

VSCodeで1.で作ったgit管理下のフォルダをワークスペースとして開く WSLのターミナルを開き、以下コマンドを実行

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

3. sail up

./vendor/bin/sail up

失敗

https://laracasts.com/discuss/channels/laravel/sail-build-fails-1?page=1&replyId=774578 の現象が発生 https://github.com/laravel/sail/issues/173#issuecomment-963947499 で解決するとのことだが、 composer update で以下が発生

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - phpunit/phpunit 9.5.x-dev requires ext-dom * -> the requested PHP extension dom is missing from your system.
    - phpunit/phpunit 9.5.9 requires ext-dom * -> the requested PHP extension dom is missing from your system.
~(略)~

https://qiita.com/yamauchi_k/items/63e38ded0eb8571fabfd を参考に、PHP extension domをインストール

sudo apt-get install php7.4-dom

その後、再び、 composer update をして、多分解決できた。

次の解決ステップとして、Laravelを8.1に上げる。上げ方は、docker-compose.ymlcontext: ./vendor/laravel/sail/runtimes/8.0context: ./vendor/laravel/sail/runtimes/8.1 に変える。 image にも 8.0 の記述があったので、ついでにそちらも 8.1 に変更。 それから、sailコマンドでビルドする。

./vendor/bin/sail build

Successfully builtが出たら、成功。 それから、sailで改めて起動。

./vendor/bin/sail up

4.APP_KEY生成

WSL上で以下を実行

./vendor/bin/sail php artisan key:generate

5.DB_HOST変更

.env を修正

DB_HOST=mysql

Application key set successfully. で成功

ref

https://chigusa-web.com/blog/laravel-github-clone/