Vagrant is a tool that manages oracle virtual boxesphp
1.本地下载https://atlas.hashicorp.com/laravel/boxes/homestead/versions/0.2.6/providers/virtualbox.box下载该box做为base,node
(https://atlas.hashicorp.com/boxes/search?utf8=%E2%9C%93&sort=&provider=&q=homestead能够用来查询有哪些box)linux
https://atlas.hashicorp.com/antoniofrignani/boxes/laravel-homestead-settler-32/versions/0.1.1/providers/virtualbox.boxios
2.本地添加 vagrant box add laravel/homestead (path to downloaded file)(base box above!)nginx
3.git clone https://github.com/laravel/homestead.git Homestead
laravel
4.运行init.sh将生成Homestead.yaml配置文件(实际上在Homestead目录将建立Vagrantfile,Homestead.yaml只是populate这个vagrantfile的脚本,方便配置(至关于执行vagrant init)git
5.配置相关参数github
http://laravel.com/docs/5.1/homesteadshell
6.vagrant up便可使用了(直接调用virtualbox的api将基于base box的vagrantfile表明的客制化环境(shared folder,network,memroy,forwarded ports etc)运行起来)npm
https://phphub.org/topics/2
Homestead 包括如下两个东西
windows下若是出现解压错误,那么可使用一下方法解决
The executable 'bsdtar' Vagrant is trying to run was not found in the %PATH% variable. This is an error. Please verify this software is installed and on the path.
解决方案是从sourceforge.net下载一个bsdtar.exe basic_bsdtar.exe from here http://sourceforge.net/projects/mingw/files/MinGW/Extension/bsdtar/ and rename it to bsdtar.exe and place it in C:\HashiCorp\Vagrant\embedded\gnuwin32\bin\
在win7中,当vagrant up时出现以下错误:
Unable to load R3 module D:\Program Files\Oracle\VirtualBox/VBoxDD.dll (VBoxDD):GetLastError=1790 (VERR_UNRESOLVED_ERROR)
则多是由于
本目录中的如下三个文件是原始的未被破解的WIN7 64位系统主题文件:
themeservice.dll
themeui.dll
uxtheme.dll这三个文件被破解所致使的。解决方案是恢复它,参考:http://download.csdn.net/download/friendan/8199047
可能的解决方案参考:
http://stackoverflow.com/questions/30090691/configuring-homestead-to-work-for-windows-users/30094439#30094439
https://github.com/npm/npm/issues/3670
https://github.com/mitchellh/vagrant/pull/5495
关于UNC的知识点: https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx#short_vs._long_names
总结一下homestead vbox的UNC name配置解决方案:
1. comment out ~/.homestead/homestead.yaml中的文件夹共享: # folders: # - map: D:\devenv\code # to: /home/vagrant/code 2. 在vagrantfile中将如下内容插入 # this should be inserted right before the "Homestead.configure()" line config.vm.provider "virtualbox" do |v, override| if Vagrant::Util::Platform.windows? override.vm.synced_folder "D:\devenv\code", "/home/vagrant/code", disabled: true v.customize ["sharedfolder", "add", :id, "--name", "code", "--hostpath", (("//?/D:/devenv/code").gsub("/","\\"))] override.vm.provision :shell, inline: "mkdir -p /home/vagrant/code" override.vm.provision :shell, inline: "mount -t vboxsf -o uid=`id -u vagrant`,gid=`getent group vagrant | cut -d: -f3` code /home/vagrant/code", run: "always" else override.vm.synced_folder "D:\devenv\code", "/home/vagrant/code" end v.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/code", "1"] end # this should be inserted right before the "Homestead.configure()" line
除了上面的使用windows UNC来解决node/bower的长文件名问题外,对于node咱们还有一种解决方案,就是使用https://github.com/arifsetiawan/flatten 这个package,来对node_modules目录进行扁平化,用法是在linux或者windows unc下完全安装node modules后,执行下面的命令:
flatten-packages PROJECT_DIRECTORY
命令完成后,就将老的node_modules所有扁平化,完全解决长文件名的问题!!!!同时该命令将删除老的垂直安排的module
通常状况下,没有必要每一个团队成员都彻底安装node,npm以及对应的node_modules,可行的措施是将node_modules自己做为一个repo,同时将node.exe文件copy到项目的root folder(就是package.json的所在目录),这样团队成员就不用安装node以及对应的package了,又能正常作build!!
windows下除了文件名长度问题外,默认若是不是以administrator运行virtualbox的话还有没法建立symlink的问题,因此通常若是使用npm,bower自动化你的测试开发流程时,可能会因为没法在windows/virtualbox之间的共享的文件夹中建立symlink而致使一些烦人的问题,一个可行的workaround是把node module, bower module等放到非windows共享文件夹中, bower能够经过.bowerc指定bower 模块安装位置, package.json以及node_modules能够放到非win目录的一个wrapper目录中。固然,也能够经过将执行vagrant up命令的命令行以administrator身份启动也可以解决windows环境下在homestead virtualbox中不能建立symbol link的问题!!!也就是说在win10下是能够建立symlink的!
在windows操做系统中,可能须要再bios中设置intel CPU的虚拟化功能使能。
vagrant up过程当中,可能出现: default: Warning: Connection timeout. Retrying..., 这时可能的解决方案是:
在vagrantfile中增长如下内容,使能gui,检查是不是停留在了grub那里:
config.vm.provider "virtualbox" do |v| v.gui = true end
还有一种解决方案是修改grub信息,给一个timeout超时。 http://segmentfault.com/a/1190000000266564出现这种错误,另一个多是你的vt没有打开,在bios中设置虚拟化有可能解决问题。还有一种方案是选择32bit的系统,具体参考: http://laravel.io/forum/05-18-2014-trouble-getting-homestead-to-start-in-windows?page=1
用 VirtualBox 面板运行该系统,在 GRUB 界面回车登陆系统,用户名:vagrant
,密码:vagrant
,编辑/etc/grub.d/00_header
,找到:
if [ "\${recordfail}" = 1 ]; then set timeout=-1
将 -1
改为 10
便可:
if [ "\${recordfail}" = 1 ]; then set timeout=10
再运行 $ update-grub
更新 GRUB,关机后再用 $ vagrant up
启动就能正常启动了。
在windows下面若是你作好了配置,hosts文件也正确,可是一直出现no input files这个错误,能够尝试vagrant up --provision,若是确实已经up状态了,
能够只执行: vagrant provision就能够了。注意只要.yaml配置文件修改了,最好都执行vagrant reload --provision
参考: https://github.com/mitchellh/vagrant/issues/3869#issuecomment-48058728 (文件自己在网盘有备份)
当你发现虚拟机开发环境客制化满意后,你能够作的事情是将该虚拟机打包成另一个box,以便提供给别人使用,提供一套统一的开发环境,确实不错哦:
vagrant package --output vagrant_example.box (在你的vagrantfile所在目录) 或者:
vagrant package xxpackage --output xxpackage.box --vagrantfile Vagrantfile
http://lovelace.blog.51cto.com/1028430/1423343
browsersync的watch/reload任务监听3000端口,可是咱们须要增长一个forwarded port在vagrantfile中,可是有时不工做,那么能够手工在virtualbox中添加端口转发就能够了。
经常使用命令:
vagrant box list
vagrant init xxBox :建立vagrantfile,而且将box信息更新为xxBox
vagrant up (在有vagrantfile的目录执行)
vagrant ssh-config :在你的vagrantfile所在目录检查该vagrant box的ssh配置信息
$ vagrant ssh-config Host default HostName 127.0.0.1 User vagrant Port 2222 UserKnownHostsFile /dev/null StrictHostKeyChecking no PasswordAuthentication no IdentityFile "c:/Documents and Settings/zhang/devenvironment/Homestead/.vagrant/machines/default/v irtualbox/private_key" IdentitiesOnly yes LogLevel FATAL
为工做方便建立一个ssh vagrant的alias,该命令等同于在homestead目录下执行vagrant ssh
alias vm="ssh vagrant@127.0.0.1 -p 2222 -i ~/devenvironment/Homestead/.vagrant/machines/default/virt
ualbox/private_key"
同时,一旦登录到系统后执行一个.postlogin.sh(cd xxx/yyy)目录,这样就很方便了(source调用上述脚本)
在homestead下也能够很是方便地建立新的sites:注意: 若是出现serve command not found错误的话,能够手工 source ~/.bashrc,也就是说上述serve命令就在.bashrc文件中定义的!!
vagrant@homestead:~$ serve trace.dev /home/vagrant/code/xdebug-trace-gui dos2unix: converting file /vagrant/scripts/serve.sh to Unix format ... nginx stop/waiting nginx start/running, process 2646 php5-fpm stop/waiting php5-fpm start/running, process 2662
alias ls='ls --color=always'