Vagrant is a tool that manages oracle virtual boxes

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.本地添加 vagrant box add laravel/homestead (path to downloaded file)(base box above!)

3.git clone https://github.com/laravel/homestead.git Homestead

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

5.配置相关参数

http://laravel.com/docs/5.1/homestead

6.vagrant up即可使用了(直接调用virtualbox的api将基于base box的vagrantfile代表的客制化环境(shared folder,network,memroy,forwarded ports etc)运行起来)

https://phphub.org/topics/2

Homestead 包括以下两个东西

  1. 一个 vagrant box 虚拟机, 里面软件什么都下载好了;
  2. Github 代码库, 里面装载着 vagrant 的配置脚本, 用来自动化配置网络, 端口映射, 等一些开发时候用到的配置;

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= (VERR_UNRESOLVED_ERROR)

则可能是因为

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

在windows下面,由于目录名称最长只有260字符,使用node gulp,grunt等模块时,往往出现Cannot mkdir: Protocol error错误

可能的解决方案参考:

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", ""]
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

homestead下node npm团队使用的实践探索

一般情况下,没有必要每个团队成员都完全安装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
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
php5-fpm stop/waiting
php5-fpm start/running, process

console下彩色显示

alias ls='ls --color=always'

laravel homestead vagrant box安装使用,问题,及相关命令的更多相关文章

  1. 解决安装laravel/homestead vagrant环境报"A VirtualBox machine with the name 'homestead' already exists."的错误

    之前在mac上安装laravel/homestead vagrant虚拟机环境时由于参照的教程是: 每次都必须在~/Homestead目录下边运行vagrant up/halt命令,觉得实在是不方便, ...

  2. 实际操作中遇到的问题--Django中查看已安装的包的相关命令

    pip freeze  --------查看已经安装的包 pip uninstall 安装包名 ---------卸载已安装的包 pip install 安装包名--------安装包

  3. linux下安装rar以及rar相关命令参数详解

    Linux平台默认是不支持RAR文件的解压,需要安装Linux版本的RAR压缩软件,下载地址:http://www.rarlab.com/download.htm 下载之后进行解压之后,进入rar目录 ...

  4. Linux for CentOS 下的 keepalived 安装与卸载以及相关命令操作之详细教程

    百度百科解释: keepalived 是一个类似于 layer3, 4 & 7 交换机制的软件,也就是我们平时说的第 3 层.第 4 层和第 7 层交换.Keepalived 的作用是检测 w ...

  5. Centos下Docker安装与使用的相关命令

    sudo yum install -y yum-utils device-mapper-persistent-data lvm2 systemctl docker status yum-config- ...

  6. 同时存在两个或多个homestead 虚拟box

    开发中发现,不同版本的homestead 里面的环境各不相同,里面的node,npm等版本都不一致,如果需要添加 不同版本的homestead同时存在可以按照以下办法处理. tips: 提供可以离线下 ...

  7. Laravel Homestead安装笔记

    引言: 最近开始学习laravel框架,了解到有个laravel homestead的box,开发起来非常方便快捷,于是就准备开始配置homestead虚拟开发环境了 什么是Homestead 要想学 ...

  8. Laravel环境配置之安装Homestead

    laravel requirements: PHP >= 5.5.9   (机器上yum安装的是5.3.3) OpenSSL PHP Extension PDO PHP Extension Mb ...

  9. Laravel Homestead安装教程

    1/先在https://www.vagrantup.com  下载vagrantup ,对应平台下载,并安装,安装后可以在命令行使用vagrant https://www.vagrantup.com/ ...

随机推荐

  1. 本地安装xssing

    本地安装xssing 环境为apache+mysql+php,linux下和Windows均进行了尝试. 步骤: (1)Mysql中创建xing数据库,将xssing.sql中的语句复制并在xing数 ...

  2. nginx js、css多个请求合并为一个请求(concat模块)

    模块介绍 mod_concat模块由淘宝开发,目前已经包含在tengine中,并且淘宝已经在使用这个nginx模块.不过塔暂时没有包含在nginx中.这个模块类似于apache中的modconcat. ...

  3. jquery offset() 与position()方法的区别

    jquery 中有两个获取元素位置的方法offset()和position(),这两个方法之间有什么异同?使用的时候应该注意哪些问题?什么时候使用offset(),什么时候又使用position()呢 ...

  4. ZOJ 1115 Digital Roots(简单,字符串与数)

    题目 //好一道水水题,可是我居然也错了那么多次,后来百度来发现是因为数据数位可能很长很长,要用字符串数组... //简单 //有坑啊——数据可能很大很大,要用字符串表示! #include<s ...

  5. sql server 存储过程,事务

    1.存储过程,事务 CREATE PROCEDURE Proc_ceshi @id int, ), @returnval int output AS BEGIN SET NOCOUNT ON; Set ...

  6. Logstash最佳实践

    http://udn.yyuap.com/doc/logstash-best-practice-cn/index.html

  7. iOS开发工具Xcode:Interface Builder

    简介: Interface Builder(IB)是Mac OS X平台下用于设计和测试用户界面(GUI)的应用程序(非开源).为了生成GUI,IB并不是必需的,实际上Mac OS X下所有的用户界面 ...

  8. Python异步IO --- 轻松管理10k+并发连接

    前言   异步操作在计算机软硬件体系中是一个普遍概念,根源在于参与协作的各实体处理速度上有明显差异.软件开发中遇到的多数情况是CPU与IO的速度不匹配,所以异步IO存在于各种编程框架中,客户端比如浏览 ...

  9. Tomcat6启用Gzip压缩功能

    配置Tomcat根目录下/conf/server.xml文件: <Connector port="8080" protocol="HTTP/1.1" co ...

  10. UVA 10943 How do you add? DP

    Larry is very bad at math — he usually uses a calculator, whichworked well throughout college. Unfor ...