Homestead
Laravelのローカル開発環境をつくる
目標
macOS上にリポジトリを作り、それを編集する
IDEを使いたい
gitの操作はmocOS上の環境で行いたい
実行はHomestead上のVMで行う
macOSの環境は汚したくない
Homesteadの初期設定
前提
zshvagrant 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
を設定する
プロジェクト作成後、 $EDITOR ~/Homestead/homestead.yaml
を自分の都合のいいように設定する
homestead.yamlfolders:
- map: ~/path/to/laravel-project-on-you-rmac
to: /home/vagrant/code
起動
~/Homestead
で
vagrant up
hosts書く
sudo vim /etc/hosts
hosts192.168.10.10 homestead.test
参考:
サーバにSSH接続する
vagrant ssh
プロジェクトを追加したい
homestead.yamlに追加して/etc/hostsにホストを追加する
初回のプロジェクトをcode以下に作ると対称的な書き方ではなくなってしまって一貫性がなくなる
homestead.yamlfolders:
- 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で確認
トラブルシュート
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にないのでコードを読む必要がある