您的位置:首页 > 编程语言 > PHP开发

laravel homestead vagrant box安装使用,问题,及相关命令

2015-06-11 00:42 1001 查看
Vagrantisatoolthatmanagesoraclevirtualboxes

1.本地下载https://atlas.hashicorp.com/laravel/boxes/homestead/versions/0.2.6/providers/virtualbox.box下载该box作为base,

(https://atlas.hashicorp.com/boxes/search?utf8=%E2%9C%93&sort=&provider=&q=homestead可以用来查询有哪些box)
https://atlas.hashicorp.com/antoniofrignani/boxes/laravel-homestead-settler-32/versions/0.1.1/providers/virtualbox.box
2.本地添加vagrantboxaddlaravel/homestead(pathtodownloadedfile)(baseboxabove!)

3.
gitclonehttps://github.com/laravel/homestead.gitHomestead


4.运行init.sh将生成Homestead.yaml配置文件(实际上在Homestead目录将创建Vagrantfile,Homestead.yaml只是populate这个vagrantfile的脚本,方便配置(相当于执行vagrantinit)

5.配置相关参数
http://laravel.com/docs/5.1/homestead
6.vagrantup即可使用了(直接调用virtualbox的api将基于basebox的vagrantfile代表的客制化环境(sharedfolder,network,memroy,forwardedportsetc)运行起来)
https://phphub.org/topics/2
Homestead包括以下两个东西

一个vagrantbox虚拟机,里面软件什么都下载好了;

Github代码库,里面装载着vagrant的配置脚本,用来自动化配置网络,端口映射,等一些开发时候用到的配置;

windows下如果出现解压错误,那么可以使用一下方法解决

Theexecutable'bsdtar'Vagrantistryingtorunwasnot
foundinthe%PATH%variable.Thisisanerror.Pleaseverify
thissoftwareisinstalledandonthepath.


解决方案是从sourceforge.net下载一个bsdtar.exebasic_bsdtar.exefromherehttp://sourceforge.net/projects/mingw/files/MinGW/Extension/bsdtar/andrenameittobsdtar.exeandplaceitinC:\HashiCorp\Vagrant\embedded\gnuwin32\bin\

在win7中,当vagrantup时出现如下错误:

UnabletoloadR3moduleD:\ProgramFiles\Oracle\VirtualBox/VBoxDD.dll(VBoxDD):GetLastError=1790(VERR_UNRESOLVED_ERROR)


则可能是因为

本目录中的以下三个文件是原始的未被破解的WIN764位系统主题文件:
themeservice.dll
themeui.dll
uxtheme.dll这三个文件被破解所导致的。解决方案是恢复它,参考:http://download.csdn.net/download/friendan/8199047

在windows下面,由于目录名称最长只有260字符,使用nodegulp,grunt等模块时,往往出现Cannotmkdir:Protocolerror错误

可能的解决方案参考:
http://stackoverflow.com/questions/30090691/configuring-homestead-to-work-for-windows-users/30094439#30094439https://github.com/npm/npm/issues/3670https://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
总结一下homesteadvbox的UNCname配置解决方案:

1.commentout~/.homestead/homestead.yaml中的文件夹共享:
#folders:
#-map:D:\devenv\code
#to:/home/vagrant/code
2.在vagrantfile中将以下内容插入
#thisshouldbeinsertedrightbeforethe"Homestead.configure()"line
config.vm.provider"virtualbox"do|v,override|
ifVagrant::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-tvboxsf-ouid=`id-uvagrant`,gid=`getentgroupvagrant|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
#thisshouldbeinsertedrightbeforethe"Homestead.configure()"line


除了上面的使用windowsUNC来解决node/bower的长文件名问题外,对于node我们还有一种解决方案,就是使用https://github.com/arifsetiawan/flatten这个package,来对node_modules目录进行扁平化,用法是在linux或者windowsunc下彻底安装nodemodules后,执行下面的命令:

flatten-packagesPROJECT_DIRECTORY


命令完成后,就将老的node_modules全部扁平化,彻底解决长文件名的问题!!!!同时该命令将删除老的垂直安排的module

homestead下nodenpm团队使用的实践探索

一般情况下,没有必要每个团队成员都完全安装node,npm以及对应的node_modules,可行的措施是将node_modules本身作为一个repo,同时将node.exe文件copy到项目的rootfolder(就是package.json的所在目录),这样团队成员就不用安装node以及对应的package了,又能正常做build!!

windows下除了文件名长度问题外,默认如果不是以administrator运行virtualbox的话还有无法创建symlink的问题,所以一般如果使用npm,bower自动化你的测试开发流程时,可能会由于无法在windows/virtualbox之间的共享的文件夹中创建symlink而导致一些烦人的问题,一个可行的workaround是把nodemodule,bowermodule等放到非windows共享文件夹中,bower可以通过.bowerc指定bower模块安装位置,package.json以及node_modules可以放到非win目录的一个wrapper目录中。当然,也可以通过将执行vagrantup命令的命令行以administrator身份启动也能够解决windows环境下在homesteadvirtualbox中不能创建symbollink的问题!!!也就是说在win10下是可以创建symlink的!

在windows操作系统中,可能需要再bios中设置intelCPU的虚拟化功能使能。

vagrantup过程中,可能出现:default:Warning:Connectiontimeout.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
settimeout=-1

-1
改成
10
即可:

if["\${recordfail}"=1];then
settimeout=10

再运行
$update-grub
更新GRUB,关机后再用
$vagrantup
启动就能正常启动了。


在windows下面如果你做好了配置,hosts文件也正确,但是一直出现noinputfiles这个错误,可以尝试vagrantup--provision,如果确实已经up状态了,

可以只执行:vagrantprovision就可以了。注意只要.yaml配置文件修改了,最好都执行vagrantreload--provision

参考:https://github.com/mitchellh/vagrant/issues/3869#issuecomment-48058728(文件本身在网盘有备份)

当你发现虚拟机开发环境客制化满意后,你可以做的事情是将该虚拟机打包成另外一个box,以便提供给别人使用,提供一套统一的开发环境,确实不错哦:

vagrantpackage--outputvagrant_example.box(在你的vagrantfile所在目录)或者:
vagrantpackagexxpackage--outputxxpackage.box--vagrantfileVagrantfile

http://lovelace.blog.51cto.com/1028430/1423343
browsersync的watch/reload任务监听3000端口,但是我们需要增加一个forwardedport在vagrantfile中,但是有时不工作,那么可以手工在virtualbox中添加端口转发就可以了。

常用命令:

vagrantboxlist

vagrantinitxxBox:创建vagrantfile,并且将box信息更新为xxBox

vagrantup(在有vagrantfile的目录执行)

vagrantssh-config:在你的vagrantfile所在目录检查该vagrantbox的ssh配置信息

$vagrantssh-config
Hostdefault
HostName127.0.0.1
Uservagrant
Port2222
UserKnownHostsFile/dev/null
StrictHostKeyCheckingno
PasswordAuthenticationno
IdentityFile"c:/DocumentsandSettings/zhang/devenvironment/Homestead/.vagrant/machines/default/v
irtualbox/private_key"
IdentitiesOnlyyes
LogLevelFATAL


为工作方便创建一个sshvagrant的alias,该命令等同于在homestead目录下执行vagrantssh

aliasvm="sshvagrant@127.0.0.1-p2222-i~/devenvironment/Homestead/.vagrant/machines/default/virt
ualbox/private_key"

同时,一旦登陆到系统后执行一个.postlogin.sh(cdxxx/yyy)目录,这样就很方便了(source调用上述脚本)

在homestead下也可以非常方便地创建新的sites:注意:如果出现servecommandnotfound错误的话,可以手工
source~/.bashrc,也就是说上述serve命令就在.bashrc文件中定义的!!


vagrant@homestead:~$servetrace.dev/home/vagrant/code/xdebug-trace-gui
dos2unix:convertingfile/vagrant/scripts/serve.shtoUnixformat...
nginxstop/waiting
nginxstart/running,process2646
php5-fpmstop/waiting
php5-fpmstart/running,process2662


console下彩色显示

aliasls='ls--color=always'
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: