Laravel之homestead安裝法

一個(gè)優(yōu)雅的web藝術(shù)家

Laravel之homestead安裝法

Laravel據(jù)說(shuō)是目前最優(yōu)雅的php web框架,雖然它沒(méi)有durpal速蕊、wordpress那么豐富份名,但正因?yàn)樗?jiǎn)潔、快速的開(kāi)發(fā)方式,使得大家都非常容易入門,并且作為未來(lái)的吃飯工具,也是可以勝任的训唱。
(注:  這是關(guān)于laravel最基礎(chǔ)的部分褥蚯,用它來(lái)自學(xué)或 者教學(xué)都非常棒挚冤。)

開(kāi)始--安裝

服務(wù)器要求

Laravel對(duì)服務(wù)器的要求不高,一般情況下用一些php平臺(tái)赞庶,如phpstudy等训挡,但是它有一個(gè)專門針對(duì)的本地開(kāi)發(fā)環(huán)境--Larval homestead,可以滿足所有的要求歧强。

1澜薄、準(zhǔn)備

安裝virtualbox和vagrant
我的系統(tǒng)在搭建linux和drupal時(shí)已經(jīng)安裝過(guò)了(建議下載最新的版本,以保證適配)摊册,通過(guò)powershell可以用命令:

Get WmiObject Class Win32_Product | Select Object Property Name

查看肤京,我的版本是Oracle VM VirtualBox 4.1.44、 Vagrant 1.7.2。

2忘分、安裝和配置

新建項(xiàng)目所在路徑棋枕,我的d:\data\vargant_box
用poweshell進(jìn)入項(xiàng)目路徑,敲入命令下載box妒峦,

PS D:\data\vagrant_box> vagrant box add laravel/homestead
==> box: Loading metadata for box 'laravel/homestead'
    box: URL: https://atlas.hashicorp.com/laravel/homestead
This box can work with multiple providers! The providers that it
can work with are listed below. Please review the list and choose
the provider you will be working with.


1) virtualbox
2) vmware_desktop


Enter your choice: 1
==> box: Adding box 'laravel/homestead' (v0.4.4) for provider: virtualbox
    box: Downloading: https://atlas.hashicorp.com/laravel/boxes/homestead/versions/0.4.4/providers/virtualbox.box
    box: Progress: 0% (Rate: 0curl:/s, Estimated time remaining: --:--:--)

上面的下載會(huì)很慢重斑,也可以使用工具從上面提供的下載的地址中直接下載。
可以用迅雷下載后肯骇,確定好box的后綴窥浪,


PS D:\data\vagrant_box> vagrant box add -n laravel d:/data/vagrant_box/hc-download.box
==> box: Adding box 'laravel' (v0) for provider:
    box: Downloading: file://d:/data/vagrant_box/hc-download.box
    box: Progress: 100% (Rate: 213M/s, Estimated time remaining: --:--:--)
==> box: Successfully added box 'laravel' (v0) for 'virtualbox'!

接下來(lái),大家就可以在虛擬機(jī)環(huán)境中運(yùn)行l(wèi)aravel了笛丙!

2.1 把box添加到vagrant box列表中
1漾脂、打開(kāi)命令行,進(jìn)入box下載的路徑(我是通過(guò)迅雷下載的)
box存放的路徑
2胚鸯、 vagrant box add laravel/homestead hc-download.box
添加box
3符相、查看一下是否添加成功
PS D:\data\vagrant_box> vagrant box add laravel/homestead hc-download.box
==> box: Adding box 'laravel/homestead' (v0) for provider:
    box: Downloading: file://D:/data/vagrant_box/hc-download.box
    box: Progress: 100% (Rate: 14.7M/s, Estimated time remaining: --:--:--)
==> box: Successfully added box 'laravel/homestead' (v0) for 'virtualbox'!
PS D:\data\vagrant_box> vagrant box list
drupalbox         (virtualbox, 0)
laravel/homestead (virtualbox, 0)
4、克隆laravel在github上的homestead項(xiàng)目

新建laravel目錄蠢琳,從github把homestead項(xiàng)目克隆下來(lái)啊终,并命令為Homestead
PS D:\data\laravel> git clone https://github.com/laravel/homestead.git Homestead
克隆完畢,我們可以在laravel文件夾下看到克隆的目錄:

克隆的目錄

運(yùn)行init.bat(windows),linux運(yùn)行init.sh
成功后傲须,我們會(huì)在c盤的如下目錄下看到:

找到homestead.yaml

5蓝牲、打開(kāi)Homestead.yaml文件,配置homestead

---
ip: "192.168.10.10"
memory: 2048
cpus: 1
provider: virtualbox

authorize: ~/.ssh/id_rsa.pub

keys:
    - ~/.ssh/id_rsa

folders:
# 修改為本地主機(jī)laravel的源碼位置
    - map: D:\data\laravel\code
      to: /home/vagrant/Code

sites:
    - map: homestead.app
    #注意本地主機(jī)的public的路徑泰讽,它并沒(méi)有l(wèi)aravel這個(gè)根例衍。
      #to: /home/vagrant/Code/Laravel/public
     #修改為:
      to: /home/vagrant/Code/public

databases:
    - homestead

# blackfire:
#     - id: foo
#       token: bar
#       client-id: foo
#       client-token: bar

# ports:
#     - send: 50000
#       to: 5000
#     - send: 7777
#       to: 777
#       protocol: udp
6、修改box版本已卸,避免無(wú)法運(yùn)行headstead的box
修改box版本號(hào)

如果提示:

PS D:\data\laravel\homestead> vagrant up
This Vagrant environment has specified that it requires the Vagrant
version to satisfy the following version requirements:

  >= 1.8.4

You are running Vagrant 1.7.2, which does not satisfy
these requirements. Please change your Vagrant version or update
the Vagrantfile to allow this Vagrant version. However, be warned
that if the Vagrantfile has specified another version, it probably has
good reason to do so, and changing that may cause the environment to
not function properly.

則是vagrant版本舊了佛玄,直接從官網(wǎng)下載最新的vagrant安裝覆蓋即可。

如果出現(xiàn)

D:/HashiCorp/Vagrant/embedded/lib/ruby/2.2.0/psych.rb:370:in `parse': (<unknown>): found a tab character that violate intendation while scanning a plain scalar at line 17 column 12 (Psych::SyntaxError)
        from D:/HashiCorp/Vagrant/embedded/lib/ruby/2.2.0/psych.rb:370:in `parse_stream'
        from D:/HashiCorp/Vagrant/embedded/lib/ruby/2.2.0/psych.rb:318:in `parse'
        from D:/HashiCorp/Vagrant/embedded/lib/ruby/2.2.0/psych.rb:245:in `load'
        from D:/data/laravel/Homestead/Vagrantfile:25:in `block in <top (required)>'
        from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.8.5/lib/vagrant/config/v2/loader.rb:37:in `call'
        from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.8.5/lib/vagrant/config/v2/loader.rb:37:in `load'
        from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.8.5/lib/vagrant/config/loader.rb:113:in `block (2 levels) in load'
        from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.8.5/lib/vagrant/config/loader.rb:107:in `each'
        from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.8.5/lib/vagrant/config/loader.rb:107:in `block in load'
        from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.8.5/lib/vagrant/config/loader.rb:104:in `each'
        from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.8.5/lib/vagrant/config/loader.rb:104:in `load'
        from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.8.5/lib/vagrant/vagrantfile.rb:28:in `initialize'
        from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.8.5/lib/vagrant/environment.rb:740:in `new'
        from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.8.5/lib/vagrant/environment.rb:740:in `vagrantfile'
        from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.8.5/lib/vagrant/environment.rb:486:in `host'
        from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.8.5/lib/vagrant/environment.rb:208:in `block in action_runner'
        from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.8.5/lib/vagrant/action/runner.rb:33:in `call'
        from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.8.5/lib/vagrant/action/runner.rb:33:in `run'
        from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.8.5/lib/vagrant/environment.rb:473:in `hook'
        from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.8.5/lib/vagrant/environment.rb:722:in `unload'
        from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.8.5/bin/vagrant:177:in `ensure in <main>'
        from D:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.8.5/bin/vagrant:177:in `<main>'
        ```
則考慮yaml文件出錯(cuò)累澡。這里指第17行有語(yǔ)法錯(cuò)誤梦抢。

###### 最后終于成功運(yùn)行,
運(yùn)行成功提示:

PS D:\data\laravel\homestead> vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'laravel/homestead' is up to date...
==> default: A newer version of the box 'laravel/homestead' is available! You currently
==> default: have version '0'. The latest is version '0.4.0'. Run
==> default: vagrant box update to update.
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
default: Adapter 2: hostonly
==> default: Forwarding ports...
default: 80 (guest) => 8000 (host) (adapter 1)
default: 443 (guest) => 44300 (host) (adapter 1)
default: 3306 (guest) => 33060 (host) (adapter 1)
default: 5432 (guest) => 54320 (host) (adapter 1)
default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
default: The guest additions on this VM do not match the installed version of
default: VirtualBox! In most cases this is fine, but in rare cases it can
default: prevent things such as shared folders from working properly. If you see
default: shared folder errors, please make sure the guest additions within the
default: virtual machine match the version of VirtualBox you have installed on
default: your host and reload your VM.
default:
default: Guest Additions Version: 5.0.12
default: VirtualBox Version: 5.1
==> default: Setting hostname...
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
default: /vagrant => D:/data/laravel/Homestead
default: /home/vagrant/Code => D:/data/laravel/code
==> default: Machine already provisioned. Run vagrant provision or use the --provision
==> default: flag to force provisioning. Provisioners marked to run always will still run.


###### 進(jìn)一步測(cè)試:

PS D:\data\laravel\homestead> vagrant ssh
Welcome to Ubuntu 14.04.4 LTS (GNU/Linux 3.19.0-25-generic x86_64)

在本地瀏覽器輸入192.168.10.10愧哟,則可訪問(wèn)到laravel站點(diǎn)奥吩。

![預(yù)覽laravel](http://upload-images.jianshu.io/upload_images/2675266-e729171a7c19e7d0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
###### 總結(jié)經(jīng)驗(yàn):
* 64位系統(tǒng)中,運(yùn)行64位的虛擬機(jī)要確保配置正確

![配置virtualbox](http://upload-images.jianshu.io/upload_images/2675266-3f3f14614cf22d3b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
* windows的Hyper V要關(guān)閉蕊梧,否則起沖突霞赫,而且360安裝中心的晶核防護(hù)也會(huì)占用虛擬技術(shù)。
* 本地機(jī)的地址也要正確分配肥矢,一般要能連上網(wǎng)或者自己設(shè)定固定IP端衰。



##### 3、開(kāi)發(fā)方式:
* 通過(guò)ssh在命令行里進(jìn)行操作
* 因?yàn)槲覀児蚕砹吮镜匚募A,因此可以直接在本地windows上進(jìn)行開(kāi)發(fā)旅东。
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末惕味,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子玉锌,更是在濱河造成了極大的恐慌名挥,老刑警劉巖,帶你破解...
    沈念sama閱讀 219,110評(píng)論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件主守,死亡現(xiàn)場(chǎng)離奇詭異禀倔,居然都是意外死亡,警方通過(guò)查閱死者的電腦和手機(jī)参淫,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,443評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門救湖,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái),“玉大人涎才,你說(shuō)我怎么就攤上這事鞋既。” “怎么了耍铜?”我有些...
    開(kāi)封第一講書人閱讀 165,474評(píng)論 0 356
  • 文/不壞的土叔 我叫張陵邑闺,是天一觀的道長(zhǎng)。 經(jīng)常有香客問(wèn)我棕兼,道長(zhǎng)陡舅,這世上最難降的妖魔是什么? 我笑而不...
    開(kāi)封第一講書人閱讀 58,881評(píng)論 1 295
  • 正文 為了忘掉前任伴挚,我火速辦了婚禮靶衍,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘茎芋。我一直安慰自己颅眶,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,902評(píng)論 6 392
  • 文/花漫 我一把揭開(kāi)白布田弥。 她就那樣靜靜地躺著涛酗,像睡著了一般。 火紅的嫁衣襯著肌膚如雪皱蹦。 梳的紋絲不亂的頭發(fā)上煤杀,一...
    開(kāi)封第一講書人閱讀 51,698評(píng)論 1 305
  • 那天眷蜈,我揣著相機(jī)與錄音沪哺,去河邊找鬼。 笑死酌儒,一個(gè)胖子當(dāng)著我的面吹牛辜妓,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 40,418評(píng)論 3 419
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼籍滴,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼酪夷!你這毒婦竟也來(lái)了?” 一聲冷哼從身側(cè)響起孽惰,我...
    開(kāi)封第一講書人閱讀 39,332評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤晚岭,失蹤者是張志新(化名)和其女友劉穎,沒(méi)想到半個(gè)月后勋功,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體坦报,經(jīng)...
    沈念sama閱讀 45,796評(píng)論 1 316
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,968評(píng)論 3 337
  • 正文 我和宋清朗相戀三年狂鞋,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了片择。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 40,110評(píng)論 1 351
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡骚揍,死狀恐怖字管,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情信不,我是刑警寧澤嘲叔,帶...
    沈念sama閱讀 35,792評(píng)論 5 346
  • 正文 年R本政府宣布,位于F島的核電站抽活,受9級(jí)特大地震影響借跪,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜酌壕,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,455評(píng)論 3 331
  • 文/蒙蒙 一掏愁、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧卵牍,春花似錦果港、人聲如沸。這莊子的主人今日做“春日...
    開(kāi)封第一講書人閱讀 32,003評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至释牺,卻和暖如春萝衩,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背没咙。 一陣腳步聲響...
    開(kāi)封第一講書人閱讀 33,130評(píng)論 1 272
  • 我被黑心中介騙來(lái)泰國(guó)打工猩谊, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人祭刚。 一個(gè)月前我還...
    沈念sama閱讀 48,348評(píng)論 3 373
  • 正文 我出身青樓牌捷,卻偏偏與公主長(zhǎng)得像墙牌,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子暗甥,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,047評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容

  • 話說(shuō)作為laravel的開(kāi)發(fā)者撤防,你聽(tīng)說(shuō)Homestead應(yīng)該很久了虽风,可是官方推薦的開(kāi)發(fā)環(huán)境在國(guó)內(nèi)為什么鮮有人用?我...
    學(xué)著放下閱讀 48,051評(píng)論 48 76
  • 之前安裝的homestead系統(tǒng)版本為Ubuntu14.04寄月,現(xiàn)業(yè)務(wù)需要焰情,需升級(jí)為16.04,在虛擬機(jī)中直接升級(jí)完...
    zzpwestlife閱讀 2,162評(píng)論 5 5
  • 冬天走了春天走了夏天也要走了 夏天從沉悶的午后睡醒是湘云妹妹樹(shù)下那一覺(jué)吧夏天的口水是甜的笑聲是清脆的它有大雨做的百...
    葺寶閱讀 222評(píng)論 0 2
  • 又一個(gè)晚上剥懒,來(lái)到了班級(jí)門口内舟,看著孩子們安靜的在教室里寫作業(yè),小聲討論著不懂的題目初橘,自己內(nèi)心感慨萬(wàn)千验游。可能他們并不...
    水凈閱讀 323評(píng)論 0 1