laravel官方推薦的Homestead工作環(huán)境弹澎,安裝簡(jiǎn)單撑瞧,使用方便袋励,推薦給使用laravel開發(fā)項(xiàng)目的程序猿。
本機(jī)操作系統(tǒng):64位Win10
? 一:前期工作:軟件準(zhǔn)備(下載)
1:虛擬機(jī)凳宙,推薦免費(fèi)的 VirtualBox 5.1熙揍,官網(wǎng)下載地址? |?百度網(wǎng)盤(密碼24es)
2: Vagrant,官網(wǎng)下載地址?| ?百度網(wǎng)盤(密碼uak6)
3: git近速,?官網(wǎng)下載地址?| 百度網(wǎng)盤(密碼)
4: Homestead,代碼托管在 https://github.com/laravel/homestead
說明: Homestead不是一個(gè)軟件堪旧,是laravel開發(fā)一個(gè)小項(xiàng)目削葱,基于php,c,ruby.,js開發(fā)的。
安裝方式有2 種淳梦,1是直接在github下載zip后解壓到合適的位置析砸,2是git克隆
5: vagrant的一個(gè)盒子叫做 homestead box
安裝方式2種,1是在線安裝(在國(guó)內(nèi)此方法太慢爆袍,不適用)2是下載盒子后離線安裝(推薦)
官網(wǎng)下載:https://app.vagrantup.com/boxes/search中搜索Homestead首繁,最新版本是4.0.0
下載地址是: https://vagrantcloud.com/laravel/boxes/homestead/versions/4.0.0/providers/virtualbox.box
? 二:盒子安裝
1: 安裝 VirtualBox, vagrant, git
2: 盒子安裝
a:新建安裝配置文件0000.json
內(nèi)容如下
{
? ? "name": "laravel/homestead",? ? "versions": [{
? ? ? ? "version": "4.0.0",
? ? ? ? "providers": [{
? ? ? ? ? ? "name": "virtualbox",
? ? ? ? ? ? "url": "04_homesteadbox400"
? ? ? ? }]
? ? }]
}b: 將盒子安裝配置文件0000.json和盒子04_homesteadbox400作郭,放在同一個(gè)文件夾下,只要改文件夾不含中文就行弦疮,如放在E:/abc def/下(文件夾有空格也沒關(guān)系)
說明1:0000.json是安裝盒子時(shí)讀取的盒子安裝配置文件夹攒,名字任取,只要格式是json的就行了胁塞。
說明2:04_homesteadbox400是box文件咏尝,名字也可以改的
說明3:? 配置文件和盒子文件最好放在同一個(gè)文件夾中,這兩個(gè)文件在安裝完后是可以刪除的(此處改為:配置文件0000.json最好保留),所在文件夾名不能是中文啸罢,有空格可以编检,如E:/abc def/0000.json可以
說明4:盒子安裝在用戶目錄C:\Users\用戶名\.vagrant.d\boxes中,我的用戶名是 Administrator
說明5:顯示安裝了哪些>vagrant box list扰才,刪除某個(gè)box命令是 C:\Users\Administrator>vagrant box remove laravel/homestead
說明6:如果不知道哪里下載box允懂,請(qǐng)先用 vagrant box add laravel/homestead,會(huì)顯示從哪里下載衩匣,因?yàn)樵诰€下載實(shí)在太慢蕾总,可改用迅雷下載下來后改名為配置文件中指定的名字
D:\homestead>vagrant box add 0000.json
? 三:homestead安裝和配置
說明1: homestead是laravel開發(fā)的一個(gè)項(xiàng)目,托管在https://github.com/laravel/homestead舵揭,可以安裝在任何位置谤专,我喜歡安裝在D盤的根目錄下,可以下載zip文件解壓也可以直接git clone安裝
說明2: homestead的版本必須與下載的box版本一樣午绳,當(dāng)前homestead的版本與box的版本是4.0.0
說明3: homestead不要放在有 “下劃線或空格" 的文件夾下面置侍,虛擬機(jī)在加載共享文件夾時(shí)會(huì)忽略
D:\www2018>git clone https://github.com/laravel/homestead.git
將homestead配置文件從D:\www2018\homestead\resources\Homestead.yaml拷貝到D:\www2018\homestead,也可執(zhí)行init.bat自動(dòng)拷貝
D:\www2018\homestead>init
編輯配置文件Homestead.yaml
編輯文件C:\Windows\System32\drivers\etc\hosts
? 四:vagrant 啟動(dòng)
vagrant在啟動(dòng)時(shí)要讀取它相應(yīng)的配置文件 Vagrantfile,查找配置文件的順序官網(wǎng)這樣說: https://www.vagrantup.com/docs/vagrantfile/#lookup-path 拦焚,首先在當(dāng)前項(xiàng)目中找蜡坊,當(dāng)前項(xiàng)目中沒有就到父目錄中找。但laravel/homestead項(xiàng)目中已經(jīng)定義好了Vagrantfile了赎败,是用ruby寫的秕衙,這個(gè)文件會(huì)讀取script中的文件,所以建議當(dāng)前vagrant工作目錄為Vagrantfile所在目錄
另外要注意的是僵刮,一定要保證C盤有足夠的空間
D:\www2018\homestead>vagrant up
最后補(bǔ)充一點(diǎn)就是据忘,如果錯(cuò)誤提示
?> Check your Homestead.yaml file, the path to your private key does not exist.
說明你電腦沒有生成ssh密鑰,要生成密鑰搞糕,前提是你電腦安裝了git勇吊,安裝后在Git安裝目錄\usr\bin(我電腦上是D:\Program Files\Git\usr\bin)下有一個(gè)ssh-keygen.exe文件,執(zhí)行這個(gè)文件就可以窍仰,
```
D:\Program Files\Git\usr\bin>ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/qianjin.DESKTOP-GVP6V4L/.ssh/id_rsa):
Created directory '/c/Users/qianjin.DESKTOP-GVP6V4L/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/qianjin.DESKTOP-GVP6V4L/.ssh/id_rsa.
Your public key has been saved in /c/Users/qianjin.DESKTOP-GVP6V4L/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:6rY8ncNu8m2V8RRPfYrezEqsIG+Lsi3H0EVfXMsBIDk qianjin@DESKTOP-GVP6V4L
The key's randomart image is:
+---[RSA 2048]----+
|? ? ? ? ...o.oo .|
|? ? ? ? E.? o..o+|
|? ? ? . o . .o=.|
|? ? ? ? . . o o .|
|? ? . .S? o O? |
|? ? . o..? * =? |
|? ? o.= o + .? |
|? ? o+*.O.o .? ? |
|? ? .**O++.? ? ? |
+----[SHA256]-----+
```
會(huì)在當(dāng)前用戶目錄/c/Users/today.DESKTOP-GVP6V4L/.ssh/(如果管理員登錄是C:\Users\Administrator\.ssh)下面生成2個(gè)文件id_rsa和id_rsa.pub
常見問題
1: A VirtualBox machine with the name 'homestead-7' already exists.Please use another name or delete the machine with the existing name, and try again.
解決:?
? ? D:\03www2018\homestead>vagrant global-status
? ? id? ? ? name? ? ? ? provider? state? ? directory
? ? -----------------------------------------------------------------------------
? ? 900a608? homestead-7 virtualbox running? D:/03_www2018/homestead
? ? 48f672c? homestead-7 virtualbox poweroff D:/03www2018/homestead
? ? The above shows information about all known Vagrant environments
? ? on this machine. This data is cached and may not be completely
? ? up-to-date. To interact with any of the machines, you can go to
? ? that directory and run Vagrant, or you can use the ID directly
? ? with Vagrant commands from any directory. For example:
? ? "vagrant destroy 1a2b3c4d"
先使用vagrant box remove xxx?刪除當(dāng)前盒子汉规,再vagrant global-status看有哪個(gè)虛擬盒子存在,使用vagrant destroy xx刪除驹吮,再使用vagrant box add 0000.json的方式重新安裝盒子
上面處理還是報(bào)錯(cuò)针史?
最終解決辦法是使用VBoxManage來刪除
D:\Program Files\Oracle\VirtualBox>VBoxManage list vms
"homestead-7" {84452234-fb51-48a5-bedd-72fda9e99664}
"virtualbox_default_1508157323631_85955_1509326648170_26616" {a12e995a-6193-4370-b06f-0f01b6a2fe08}
D:\Program Files\Oracle\VirtualBox>VBoxManage unregistervm homestead-7 --delete
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%