先にざっくり概要
- VirtualBoxを入れる
- Vagrantを入れる
- Git for Windowsを入れる
- HomesteadのVagrant boxをダウンロード
- Homesteadのgitリポジトリをclone
- init.batを起動
- 環境変数を設定
- ssh-keygenで鍵を作成
- Homestead.yamlを編集
- vagrant upでVMを起動
- vagrant sshで接続
- laravelプロジェクトを作成
- ホスト環境からブラウザで確認
詳細な手順
VirtualBoxを入れる
以下からどうぞ.
Vagrantを入れる
こちらも以下からどうぞ.
導入時バージョンは2.1.2.
Git for Windowsを入れる
以下からどうぞ.
コマンドプロンプトで使う設定で入れた.
HomesteadのVagrant boxをダウンロード
コマンドプロンプトで以下を実行.
> vagrant box add laravel/homestead
Homesteadのgitリポジトリをダウンロード
コマンドプロンプトの任意のディレクトリで以下を実行.
> git clone https://github.com/laravel/homestead.git Homestead
init.batを実行
上述でcloneしたリポジトリのディレクトリへ移動して以下を実行.
> init.bat
環境変数を設定
これはおすすめできないけど.
ssh-keygenしたいだけだったのだが, Git for Windows導入時に入ってくるものがコマンドプロンプトにパスが通ってないので使えない.
というわけで環境変数へ以下を追加するという暴挙に出た.
C:\Program Files\Git\usr\bin
乱暴だけどunixコマンドが使えるようになって便利かも.
ただ, findコマンドみたいに名前が被るコマンドだと......
ssh-keygenで鍵を作る
.sshディレクトリがなければ作っておきましょう.
> mkdir %HOMEPATH%\.ssh
移動してssh-keygenで鍵を作る.
> cd %HOMEPATH%\.ssh > ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (//.ssh/id_rsa): c:/Users/twinbird/.ssh/id_rsa Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in c:/Users/twinbird/.ssh/id_rsa. Your public key has been saved in c:/Users/twinbird/.ssh/id_rsa.pub.
Homestead.yamlを編集
ホームにhelloworldプロジェクトを作る前提で.
folders: - map: ~/helloworld to: /home/vagrant/helloworld sites: - map: homestead.test to: /home/vagrant/helloworld/public
vagrant up でVM起動
> cd [GitでcloneしてきたHomesteadのディレクトリ] > vagrant up
vagrant sshでVMにつなぐ
> vagrant ssh
laravelプロジェクトを作成
helloworldプロジェクトを作るとしましょう.
$ composer create-project --prefer-dist laravel/laravel helloworld
ホスト環境からブラウザで確認
ホストからブラウザで下記へアクセス.
192.168.10.10
番外
Homestead.yamlの変更が効かないんすけど
vagrantをリロードします.
vagrant reload --provision