Homestead
https://laravel.com/docs/5.7/homestead
Laravelの公式提供する開発環境
VMのイメージをVagrantで動かす
Laravelのローカル開発環境をつくる
目標
macOS上にリポジトリを作り、それを編集する
IDEを使いたい
gitの操作はmocOS上の環境で行いたい
実行はHomestead上のVMで行う
macOSの環境は汚したくない
Homesteadの初期設定
https://laravel.com/docs/5.7/homestead#installation-and-setup
前提
VagrantとVirtualBoxがインストールされている
code:zsh
vagrant box add laravel/homestead
git clone https://github.com/laravel/homestead.git ~/Homestead
cd ~/Homestead
git checkout v8.0.1 # このバージョンは時々刻々変化するので公式Docを見ること
bash init.sh
homestead.yamlを設定する
その前にLaravel Installerをつかってプロジェクトをつくる
プロジェクト作成後、$EDITOR ~/Homestead/homestead.yamlを自分の都合のいいように設定する
code:homestead.yaml
folders:
- map: ~/path/to/laravel-project-on-you-rmac
to: /home/vagrant/code
起動
~/Homesteadで
vagrant up
hosts書く
sudo vim /etc/hosts
code:hosts
192.168.10.10 homestead.test
http://homestead.test/ でWelcome Pageにアクセスできる
参考:
HomesteadはBonjourを使うとhostsの設定なしで使えるらしい(ためしてない)
サーバにSSH接続する
vagrant ssh
Xdebugつかえる
Laravel Homestead - Laravel - The PHP Framework For Web Artisans
プロジェクトを追加したい
Adding Additional Sitesのとおり
homestead.yamlに追加して/etc/hostsにホストを追加する
初回のプロジェクトをcode以下に作ると対称的な書き方ではなくなってしまって一貫性がなくなる
code:homestead.yaml
folders:
- map: ~/path/to/laravel-project-on-you-rmac
to: /home/vagrant/code
# project 2を追加
- map: ~/path/to/laravel-project2-on-you-rmac
to: /home/vagrant/project2
sites:
- map: homestead.test
to: /home/vagrant/code/public
# project 2を追加
- map: project2.test
to: /home/vagrant/project2/public
vagrant reload --provisionすれば正しくmapされる
--provisionが抜けると正しいプロジェクトにmapされないので注意
vagrant 2.2.7-devで確認
トラブルシュート
vagrant upができない上にvagrant global-statusで何も出ない
PHP 7.3.1のHomesteadでnginxがBad Gatewayになる
Composer update warning · Issue #806 · laravel/homestead
code:zsh
==> homestead-7: Running provisioner: shell...
homestead-7: Running: script: Update Composer
homestead-7: Updating to version 1.8.3 (stable channel).
homestead-7:
homestead-7:
homestead-7: ErrorException
homestead-7: rename(/home/vagrant/.composer/cache/composer-temp.phar,/usr/local/bin/composer): Permission denied
homestead-7:
homestead-7:
homestead-7: self-update -r|--rollback --clean-backups --no-progress --update-keys --stable --preview --snapshot --set-channel-only -- <version>
The SSH command responded with a non-zero exit status. Vagrant
assumes that this means the command failed. The output for this command
should be in the log above. Please read the output to determine what
went wrong.
Site Typesという設定項目があり、SPAとかが指定できるらしい
詳しい説明がdocにないのでコードを読む必要がある
https://github.com/laravel/homestead/blob/master/scripts/site-types/spa.sh