自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Windows上使用Vagrant打造Laravel Homestead可協(xié)同跨平臺開發(fā)環(huán)境

系統(tǒng) Windows 系統(tǒng)運維
本文通過Vagrant搭建一套類似Laravel Homestead完整開發(fā)環(huán)境,這樣極大的減少了架設(shè)開發(fā)環(huán)境的時間,同時還支持在Windows/Mac/Linux不同平臺上分享定制包,統(tǒng)一團(tuán)隊之間的開發(fā)環(huán)境提高工作效率,而Docker的出現(xiàn)也讓未來更值得期待。
文章目錄

1. 前言

2. 更新歷史

3. 環(huán)境準(zhǔn)備

4. 安裝git

5. 安裝php

6. 安裝Laravel

7. 安裝Composer

8. 安裝Vagrant

9. 安裝VirtualBox

10. Vagrant配置

10.1. 啟動Vagrant

10.2. 導(dǎo)出box

10.3. 其它命令

11. Laravel Homestead

[[141307]]

前言

大家對VMware或者VirtualBox一定不會陌生,虛擬化的好處自然深入人心,而現(xiàn)在我們可以通過Vagrant搭建一套類似Laravel Homestead完整開發(fā)環(huán)境,這樣極大的減少了架設(shè)開發(fā)環(huán)境的時間,同時還支持在Windows/Mac/Linux不同平臺上分享定制包,統(tǒng)一團(tuán)隊之間的開發(fā)環(huán)境提高工作效率,而Docker的出現(xiàn)也讓未來更值得期待。

用Vagrant為自己打造一個奇妙的跨平臺開發(fā)環(huán)境

更新歷史

擴展閱讀

Vagrant - https://www.vagrantup.com/
Laravel Homestead - http://laravel.com/docs/5.1/homestead
在windows下進(jìn)行l(wèi)inux開發(fā):利用Vagrant+virtualbox - http://blog.star7th.com/2015/06/1538.html
在 Mac/win7 下上使用 Vagrant 打造本地開發(fā)環(huán)境 - http://segmentfault.com/a/1190000002645737

環(huán)境準(zhǔn)備

  1. Git(非必需)
  2. PHP(非必需)
  3. Laravel(非必需)
  4. Composer(非必需)
  5. Vagrant
  6. VirtualBox

安裝git

1.下載GitHub for Windows

https://windows.github.com/

安裝php

建議大家盡量安裝當(dāng)前最新版本的 PHP

1.下載PHP

http://windows.php.net/download/

2.解壓目錄

我的路徑D:\php

3.添加環(huán)境變量

右鍵計算機->高級系統(tǒng)設(shè)置->環(huán)境變量->系統(tǒng)變量->PATH

C:\ProgramData\Oracle\Java\javapath;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\nodejs\;D:\php;C:\ProgramData\ComposerSetup\bin

4.設(shè)置php.ini

進(jìn)入 PHP 安裝目錄(例如 D:\php)。找到 php.ini-development 文件并復(fù)制一份到當(dāng)前目錄,重命名為 php.ini,修改以下配置
去掉extension=php_mbstring.dll 前面的分號(888 行左右)
去掉extension=php_openssl.dll前面的分號(893 行左右)
去掉extension_dir = "ext"前面的分號(736 行左右)

5.使環(huán)境變量生效

重啟explorer.exe

#p#

安裝Laravel

1.下載Laravel

http://www.golaravel.com/download/

2.解壓目錄

我的路徑D:\laravel-v5.1.4

3.啟動Laravel

  1. d: 
  2. cd laravel-v5.1.4 
  3. D:\laravel-v5.1.4>php artisan serve 
  4. Laravel development server started on http://localhost:8000/ 

在瀏覽器中訪問http://localhost:8000/

artisanserve 命令還支持兩個參數(shù):

host 設(shè)置主機地址
port 設(shè)置 web server 監(jiān)聽的端口號
例如:php artisan serve --port=8888

安裝Composer

1.下載Composer-Setup.exe

https://getcomposer.org/doc/00-intro.md#installation-windows

2.配置Composer

  1. Loading composer repositories with package information 
  2. Installing dependencies (including require-dev) 
  3. SSL certificate problem, verify that the CA cert is OK. Details:  
  4. error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed” 

如果安裝過程提示報錯為缺少CA證書,下載cacert.pem到自定義路徑
http://curl.haxx.se/docs/caextract.html

然后修改php.ini文件(1983行左右)

openssl.cafile=D:\php\verify\cacert.pem

3.測試Composer

  1. composer -V 
  2.  
  3. Composer version 1.0-dev (d79427f1a7b15e8f4d46ce8124a4d0c58ba1479c) 2015-07-04 11:22:58 

安裝Vagrant

1.下載Vagrant

https://www.vagrantup.com/downloads.html

2.離線下載虛擬鏡像

https://github.com/tommy-muehle/puppet-vagrant-boxes/releases/download/1.0.0/centos-6.6-x86_64.box

上面給出的是centos-6.6鏡像下載鏈接,要下載其他鏡像請訪問官網(wǎng)
http://www.vagrantbox.es/

安裝VirtualBox

BIOS里面開啟CPU硬件虛擬化支持VT(Virtualization Technology)

1.下載VirtualBox

https://www.virtualbox.org/wiki/Downloads

2.導(dǎo)入鏡像

設(shè)置VirtualBox目錄并拷貝鏡像centos-6.6-x86_64.box
E:\VirtualBox\centos-6.6-x86_64.box

3.命令初始化Vagrant

  1. #切換VirtualBox目錄 
  2. e: 
  3. cd .\VirtualBox 
  4.  
  5. #輸入命令初始化 
  6. E:\VirtualBox> vagrant init centos6.6 
  7. A `Vagrantfile` has been placed in this directory. You are now 
  8. ready to `vagrant up` your first virtual environment! Please read 
  9. the comments in the Vagrantfile as well as documentation on 
  10. `vagrantup.com` for more information on using Vagrant. 
  11.  
  12. #執(zhí)行添加命令 
  13. E:\VirtualBox> vagrant box add centos6.6 centos-6.6-x86_64.box 
  14. ==> box: Adding box 'centos6.6' (v0) for provider: 
  15.     box: Downloading: file://E:/VirtualBox/centos-6.6-x86_64.box 
  16.     box: Progress: 100% (Rate: 670M/s, Estimated time remaining: --:--:--) 
  17. ==> box: Successfully added box 'centos6.6' (v0) for 'virtualbox'
  18.  
  19. #檢查是否導(dǎo)入成功 
  20. E:\VirtualBox> vagrant box list 
  21. centos6.6 (virtualbox, 0) 

#p#

Vagrant配置

詳細(xì)配置文檔可以參考官方手冊 - https://docs.vagrantup.com/v2/

啟動Vagrant

通過Shell進(jìn)入目錄E:\VirtualBox后執(zhí)行命令

  1. vagrant up 

順利啟動的完整過程如下所示:

  1. E:\VirtualBox>vagrant up 
  2. Bringing machine 'default' up with 'virtualbox' provider... 
  3. ==> default: Importing base box 'centos6.6'... 
  4. ==> default: Matching MAC address for NAT networking... 
  5. ==> default: Setting the name of the VM: VirtualBox_default_1437213832296_68434 
  6. ==> default: Clearing any previously set forwarded ports... 
  7. ==> default: Clearing any previously set network interfaces... 
  8. ==> default: Preparing network interfaces based on configuration... 
  9.     default: Adapter 1: nat 
  10. ==> default: Forwarding ports... 
  11.     default: 22 => 2222 (adapter 1) 
  12. ==> default: Booting VM... 
  13. ==> default: Waiting for machine to boot. This may take a few minutes... 
  14.     default: SSH address: 127.0.0.1:2222 
  15.     default: SSH username: vagrant 
  16.     default: SSH auth method: private key 
  17.     default: Warning: Connection timeout. Retrying... 
  18.     default
  19.     default: Vagrant insecure key detected. Vagrant will automatically replace 
  20.     default: this with a newly generated keypair for better security. 
  21.     default
  22.     default: Inserting generated public key within guest... 
  23.     default: Removing insecure key from the guest if it's present... 
  24.     defaultKey inserted! Disconnecting and reconnecting using new SSH key... 
  25. ==> default: Machine booted and ready! 
  26. ==> default: Checking for guest additions in VM... 
  27.     default: The guest additions on this VM do not match the installed version of 
  28.     default: VirtualBox! In most cases this is fine, but in rare cases it can 
  29.     default: prevent things such as shared folders from working properly. If you see 
  30.     default: shared folder errors, please make sure the guest additions within the 
  31.     default: virtual machine match the version of VirtualBox you have installed on 
  32.     default: your host and reload your VM. 
  33.     default
  34.     default: Guest Additions Version: 4.3.28 
  35.     default: VirtualBox Version: 5.0 
  36. ==> default: Mounting shared folders... 
  37.     default: /vagrant => E:/VirtualBox 

虛擬機啟動之后則可以通過 vagrant ssh 聯(lián)入虛擬機進(jìn)行進(jìn)一步的環(huán)境配置,或者軟件安裝相關(guān)的工作,在Windows系統(tǒng)下,并不能直接通過vagrant ssh連到虛擬機,需要使用SecureCRT/Putty/Xshell等第三方工具進(jìn)行連接。連接地址127.0.0.1,端口2222。登錄的帳號root的密碼為vagrant

  1. E:\VirtualBox> vagrant up 
  2. Bringing machine 'default' up with 'virtualbox' provider... 
  3. ==> default: Clearing any previously set forwarded ports... 
  4. ==> default: Clearing any previously set network interfaces... 
  5. ==> default: Preparing network interfaces based on configuration... 
  6.     default: Adapter 1: nat 
  7.     default: Adapter 2: bridged 
  8. ==> default: Forwarding ports... 
  9.     default: 80 => 8080 (adapter 1) 
  10.     default: 22 => 2222 (adapter 1) 
  11. ==> default: Booting VM... 
  12. ==> default: Waiting for machine to boot. This may take a few minutes... 
  13. The guest machine entered an invalid state while waiting for it 
  14. to boot. Valid states are 'starting, running'. The machine is in the 
  15. 'poweroff' state. Please verify everything is configured 
  16. properly and try again. 
  17.  
  18. If the provider you're using has a GUI that comes with it, 
  19. it is often helpful to open that and watch the machine, since the 
  20. GUI often has more helpful error messages than Vagrant can retrieve. 
  21. For example, if you're using VirtualBox, run `vagrant up` while the 
  22. VirtualBox GUI is open

如果有報上述錯誤,并且運行Virtualbox去安裝系統(tǒng)時出錯:Failed to open a session for the virtual machine,Unable to load R3 module C:\Program Files\Oracle\VirtualBox/VBoxDD.DLL (VBoxDD): GetLastError=1790 (VERR_UNRESOLVED_ERROR).,需要使用UniversalThemePatcher還原未破解的themeservice.dll themeui.dll uxtheme.dll文件

已經(jīng)打包好的下載鏈接 - http://pan.baidu.com/s/1c0HGj2g

  1. ==> default: Booting VM... 
  2. ==> default: Waiting for machine to boot. This may take a few minutes... 
  3.     default: SSH address: 127.0.0.1:2222 
  4.     default: SSH username: vagrant 
  5.     default: SSH auth method: private key 
  6.     default: Warning: Connection timeout. Retrying... 
  7.     default: Warning: Connection timeout. Retrying... 
  8.     default: Warning: Connection timeout. Retrying... 

如果報default: Warning: Connection timeout. Retrying...,建議打編輯Vagrantfile打開VirtualBox圖形化界面vb.gui = true進(jìn)一步分析錯誤代碼和原因。

導(dǎo)出box

通過Shell進(jìn)入目錄E:\VirtualBox后執(zhí)行命令

  1. vagrant package 
  2.  
  3. vagrant package --output NAME --vagrantfile FILE 
  4.  
  5. #可選參數(shù): 
  6. --output NAME : (可選)設(shè)置通過NAME來指定輸出的文件名 
  7. --vagrantfile FILE:(可選)可以將Vagrantfile直接封進(jìn)box中 

完成后會在當(dāng)前目錄就會生成package.box,可以在家或者團(tuán)隊成員共享開發(fā)環(huán)境保持一致性

其它命令

vagrant up (啟動虛擬機)
vagrant halt (關(guān)閉虛擬機——對應(yīng)就是關(guān)機)
vagrant suspend (暫停虛擬機——只是暫停,虛擬機內(nèi)存等信息將以狀態(tài)文件的方式保存在本地,可以執(zhí)行恢復(fù)操作后繼續(xù)使用)
vagrant resume (恢復(fù)虛擬機 —— 與前面的暫停相對應(yīng))
vagrant box remove centos6.6 (移除box,其中centos6.6是box名)
vagrant destroy (刪除虛擬機,刪除后在當(dāng)前虛擬機所做進(jìn)行的除開Vagrantfile中的配置都不會保留)

#p#

Laravel Homestead

細(xì)節(jié)部分可參考官方文檔 - http://laravel.com/docs/5.1/homestead

1.下載安裝包

  1. vagrant box add laravel/homestead 
  2.  
  3. E:\Homestead>vagrant box add laravel/homestead 
  4. ==> box: Loading metadata for box 'laravel/homestead' 
  5.     box: URL: https://atlas.hashicorp.com/laravel/homestead 
  6. This box can work with multiple providers! The providers that it 
  7. can work with are listed below. Please review the list and choose 
  8. the provider you will be working with
  9.  
  10. 1) virtualbox 
  11. 2) vmware_desktop 
  12.  
  13. Enter your choice: 1 
  14. ==> box: Adding box 'laravel/homestead' (v0.2.7) for provider: virtualbox 
  15.     box: Downloading: https://vagrantcloud.com/laravel/boxes/homestead/versions/0.2.7/providers/virtualbox.box 
  16.     box: Progress: 0% (Rate: 9d/s, Estimated time remaining: 0:05:30)11)) 

由于國內(nèi)網(wǎng)絡(luò)環(huán)境問題建議離線下載后手動導(dǎo)入

  1. #輸入命令初始化 
  2. E:\Homestead>vagrant init laravel 
  3. A `Vagrantfile` has been placed in this directory. You are now 
  4. ready to `vagrant up` your first virtual environment! Please read 
  5. the comments in the Vagrantfile as well as documentation on 
  6. `vagrantup.com` for more information on using Vagrant. 
  7.  
  8. #執(zhí)行添加命令 
  9. E:\Homestead>vagrant box add laravel laravel.box 
  10. ==> box: Box file was not detected as metadata. Adding it directly... 
  11. ==> box: Adding box 'laravel' (v0) for provider: 
  12.     box: Unpacking necessary files from: file://E:/Homestead/laravel.box 
  13.     box: Progress: 100% (Rate: 141M/s, Estimated time remaining: --:--:--) 
  14. ==> box: Successfully added box 'laravel' (v0) for 'virtualbox'
  15.  
  16. #檢查是否導(dǎo)入成功 
  17. E:\Homestead>vagrant box list 
  18. centos6.6 (virtualbox, 0) 
  19. laravel   (virtualbox, 0) 
  20.  
  21. #啟動Lavarel Homestead 
  22. E:\Homestead>vagrant up 
  23. Bringing machine 'default' up with 'virtualbox' provider... 
  24. ==> default: Importing base box 'laravel'... 
  25. ==> default: Matching MAC address for NAT networking... 
  26. ==> default: Setting the name of the VM: Homestead_default_1437217549272_56101 
  27. ==> default: Clearing any previously set network interfaces... 
  28. ==> default: Preparing network interfaces based on configuration... 
  29.     default: Adapter 1: nat 
  30. ==> default: Forwarding ports... 
  31.     default: 22 => 2222 (adapter 1) 
  32. ==> default: Booting VM... 
  33. ==> default: Waiting for machine to boot. This may take a few minutes... 
  34.     default: SSH address: 127.0.0.1:2222 
  35.     default: SSH username: vagrant 
  36.     default: SSH auth method: private key 
  37.     default: Warning: Connection timeout. Retrying... 
  38.     default
  39.     default: Vagrant insecure key detected. Vagrant will automatically replace 
  40.     default: this with a newly generated keypair for better security. 
  41.     default
  42.     default: Inserting generated public key within guest... 
  43.     default: Removing insecure key from the guest if it's present... 
  44.     defaultKey inserted! Disconnecting and reconnecting using new SSH key... 
  45. ==> default: Machine booted and ready! 
  46. ==> default: Checking for guest additions in VM... 
  47.     default: The guest additions on this VM do not match the installed version of 
  48.     default: VirtualBox! In most cases this is fine, but in rare cases it can 
  49.     default: prevent things such as shared folders from working properly. If you see 
  50.     default: shared folder errors, please make sure the guest additions within the 
  51.     default: virtual machine match the version of VirtualBox you have installed on 
  52.     default: your host and reload your VM. 
  53.     default
  54.     default: Guest Additions Version: 4.3.14 
  55.     default: VirtualBox Version: 5.0 
  56. ==> default: Mounting shared folders... 
  57.     default: /vagrant => E:/Homestead 

登錄帳戶vagrant/vagrant,開始全新的Laravel Homestead體驗之旅吧!

 

責(zé)任編輯:火鳳凰 來源: HelloDog博客
相關(guān)推薦

2019-11-18 14:00:40

開發(fā)工具環(huán)境搭建vagrant

2018-02-07 11:15:07

Vagrant使用問題

2013-12-10 09:39:01

Windows平臺Linux開發(fā)

2018-03-02 16:30:30

2013-12-10 09:00:51

WindowsLinux開發(fā)環(huán)境

2020-10-26 09:00:00

LinuxVagrant操作系統(tǒng)

2024-02-27 18:59:55

ReactRSDWeb

2009-10-09 09:37:46

2018-03-21 14:23:39

vagrant測試環(huán)境

2021-06-29 07:14:19

NEXTCLOUDONLYOFFICE協(xié)同編輯平臺

2023-08-29 09:16:53

ElectronForge

2024-03-12 00:05:00

開發(fā)編程語言IDE

2025-01-26 08:35:01

First UI移動端開發(fā)

2009-06-01 15:56:48

eclipse sdkeclipse

2019-07-25 15:24:20

2021-03-23 09:52:39

鴻蒙HarmonyOS應(yīng)用開發(fā)

2013-02-18 10:40:55

2015-03-30 16:00:21

Windows應(yīng)用少開發(fā)工具

2012-05-22 21:56:49

Android

2015-01-14 09:41:28

跨平臺移動應(yīng)用Linux開發(fā)
點贊
收藏

51CTO技術(shù)棧公眾號