方法一:

前提条件:
Windows 用户,你可能需要启用硬件虚拟化(VT-x)。这通常需要通过 BIOS 来启用它。如果你在一个 UEFI 系统上使用的是 Hyper-V,你需要关闭 Hyper-V 才能启用 VT-x

下载安装最新版: VirtualBox 和 Vagrant

1·首先将Homestead文件夹放入到当前用户目录之下

2·然后 使用git命令工具

3·cd 切换到Homestead目录下

4·将virtualbox.box离线文件放入指定目录上

5·执行 vagrant box add laravel/homestead 加上离线文件的路径virtualbox.box
进行安装

6·初始化:
bash init.sh

7·安装好之后打开Homestead文件夹打开Homestead.yaml文件进行修改配置:
ip: “192.168.10.10”
memory: 2048
cpus: 3
provider: virtualbox

authorize: ~/.ssh/id_rsa.pub

keys:
– ~/.ssh/id_rsa

folders:
– map: F:/htdocs/Laravel
to: /home/vagrant/Code/Laravel

sites:
– map: laravel.app
to: /home/vagrant/Code/Laravel/public

databases:
– homestead

8·保存之后,加入hosts文件配置:
192.168.10.10 laravel.app
9·生成密钥:
ssh-keygen

10·vagrant up开启虚拟机

11·vagrant ssh 进入到虚拟机系统上
关闭虚拟机:
vagrant halt
查看vagrant常用命令:
vagrant

 

方法二:

1·你首先要确定你有个好的 terminal [ 终端:cmder 或 Git 的git bash ] . 注意windows的cmd不能用(个人推荐用Git bash)
2·下载和安装 [ virtualbox ] 和 [ vagrant ]前者为系统装载用的,后者为系统控制用的
3·如果你要使用 homestead 就必须要有个virtualbox.box的文件 ,官方 Laravel 下载这个文件的这个命令为vagrant box add laravel/homestead 但是因为中国的对外国网络资源的限制,你要下载这个文件可能会需要不少的时间,因此 , 在这我们拥有两个选择的余地
选择一 : 当你使用官方下载命令时,你的终端会显示这个文件的源地址复制https://atlas.hashicorp.com/laravel/boxes/homestead/,然后按 ctrl +c 退出,然后用的喜欢的下载软件下载,最好是用最新版的,因为会有各种问题.
选择二 : phphub上的 virtualbox.box
好了 , 现在我假设你已经拥有这个文件,现在来用我们的方法添加 virtualbox.box . 打开你的ide(代码编译器) ,一般为 Sublime Text 和 Atom ,为何要提编译器呢 , 因为下面的步骤可能会需要其中一个的编译器 , 创建一个名为homestead.json的文件 , 输入以下内容

{
“name”: “laravel/homestead”,
“versions”:
[
{
“version”: “1.0.1”,
“providers”: [
{
“name”: “virtualbox”,
“url”: “D:/box/virtualbox.box” //你下载的virtualbox.box在电脑系统上的位置
}
]
}
]
}
打开的 IDE (编译器) 先不要保存,点击开始菜单或 win 快捷键 , 在搜索栏处输入你的terminal ( 终端 ) , 点击鼠标右键以管理员身份运行,一般会跳转到 : 
C:\Users\windows的账户名>
然后回到 IDE (编译器) 保文件到C:\Users\windows的账户名这个目录下 , 并且命名为 homestead.json , 然后再回到terminal ( 终端 ) 输入一下代码 :
C:\Users\windows的账户名> vagrant box add homestead.json 

C:\Users\windows的账户名> vagrant box add homestead.json
==> box: Loading metadata for box 'homestead.json'
box: URL: file://C:/Users/windows的账户名/homestead.json
==> box: Adding box 'laravel/homestead' (v1.0.1) for provider: virtualbox
box: Downloading: "D:/box/virtualbox.box" //你下载的virtualbox.box在电脑上的位置
box: Progress: 100% (Rate: 129M/s, Estimated time remaining: --:--:--)
==> box: Successfully added box 'laravel/homestead' (v1.0.1) for 'virtualbox'!

然后继续 在terminal ( 终端 ) 输入.
C:\Users\windows的账户名> ssh-keygen -t rsa -C "1158624818@qq.com"
说明 : 这个命令是创建 Homestead 连接秘匙 , 因为我们是在本机上运行的所以不需要密码之类的 , 一直按回车就行

C:\Users\windows的账户名> ssh-keygen -t rsa -C "1158624818@qq.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/windows的账户名/.ssh/id_rsa):
Created directory '/c/Users/windows的账户名/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/windows的账户名/.ssh/id_rsa.
Your public key has been saved in /c/Users/windows的账户名/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:UTmPEezFQK0XUa5Km2lGnqOBgtCo5rwGGWCX8CaTN6g yenanzero@gamil.com
The key's randomart image is:
+---[RSA 2048]----+
| .. . o=*.o. |
|..+o .= =. |
|o=.= .. B .. |
|oo= . .+ o. |
|Eo. S o.. |
|+. . . + * |
|o.. . . . @ |
|+. . = . |
|.+. . |
+----[SHA256]-----+

5·现在继续 在terminal ( 终端 ) 输入.

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

说明 : 这个命令是 下载 Homestead 目录,里面包含了Homestead 的配置文件

C:\Users\windows的账户名> git clone https://github.com/laravel/homestead.git Homestead
Cloning into 'Homestead'...
remote: Counting objects: 1623, done.
rRemote: Total 1623 (delta 0)eceiving objects: 99% (1, reused 0 (delt607/1623), 244a 0), pack-reuse.01 KiB | 13.00d 1623 KiB/s
Receiving objects: 100% (1623/1623), 252.22 KiB | 13.00 KiB/s, done.
Resolving deltas: 100% (958/958), done.
Checking connectivity... done.

现在让我们来看看文件是否现在成功了,在 在terminal ( 终端 ) 输入 : 

C:\Users\windows的账户名> ls
Homestead/ //我其他文件夹就没写了,只要看到了这个文件夹你就算是把 Homestead 的配置文件下载下来了

然后继续 在terminal ( 终端 ) 输入 

C:\Users\windows的账户名 > cd Homestead
C:\Users\windows的账户名\Homestead >
C:\Users\windows的账户名\Homestead > bash init.sh //初始化 .homestead 目录

说明 : 这个bash init.sh 命令会创建一个 .homestead目录
这个目录位于C:\Users\windows的账户名\ 这个目录下
这个.homestead目录里有一个 Homestead.yaml 文件
很多人windows启动Homestead失败都是因为这个配置文件的关系
6·注意 !!!现在这个步骤很重要好了现在用 IDE(代码编译器) 打开目录地址 C:\Users\windows的账户名\ .homestead\Homestead.yaml , 你会看到如下代码


|---
| ip: "192.168.10.10"
|memory: 2048
|cpus: 1
|provider: virtualbox
|
|authorize: ~/.ssh/id_rsa.pub
|
|keys:
| - ~/.ssh/id_rsa
|
|folders:
| - map: ~/Code //这个是你的项目的地址,例如D:\随便\项目的目录 1
| to: /home/vagrant/Code //这个是homestead系统的地址 2
| //其实这就是windows和hometead两个系统共享一个文件夹,难懂一点的话叫||映射
|
|sites: //__这个是你的项目
| - map: homestead.app 这个是你项目要设定在你的浏览器上的地址 //需要设定C host文件
| to: /home/vagrant/Code/Laravel/public //这里的Laravel其实就是D:\随便\项目的目录\Laravel
|
|databases:
| - homestead
|
|# blackfire:
|# - id: foo
|# token: bar
|# client-id: foo
|# client-token: bar
|
|# ports:
|# - send: 50000
|# to: 5000
|# - send: 7777
|# to: 777
|# protocol: udp

将以上的代码修改成以下的代码

|—
|ip: “192.168.10.10”
|memory: 2048
|cpus: 1
|provider: virtualbox
|
|authorize: ~/.ssh/id_rsa.pub
|
|keys:
| – ~/.ssh/id_rsa
|
|folders:
| – map: D:\随便\项目的目录 //当启动时会自动转换成D:/随便/项目的目录,这个是正确的
| to: /home/vagrant/Code
|
|sites: //看到这你可以看到为什么是sites,而不是site
| – map: aimiliya.local 这个是你在hosts设定的网站地址
| to: /home/vagrant/Code/king/public 这里的king是你设定的D:\随便\项目的目录\king
|
| – map: lamu.local
| to: /home/vagrant/Code/lamu/public
|
| – map: leimu.local
| to: /home/vagrant/Code/leimu/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
|

提醒 : IDE(代码编译器) 记得保存 .
警告 : 以上代码为最基础的Homestead配置 ,你要进行开启其他功能最好阅读或参考 Laravel 和 vagrant官方文档
举例 : 例如在 folders 下面填写 type:“nfs” , 这对于windows 来说是错误的 , 对于 mac 来说却是成功的 , 原因vagrant不支持对 windows 开启 nfs ,具体参考 synced-folders .
7 .好了现在回到 terminal ( 终端 ) 启动吧,输入 
vagrant up
注意 : 在你以后重新启动Homestead .
即 : vagrant up都必须在 Homestead 这个目录下启动

C:\Users\windows的账户名\Homestead> vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'laravel/homestead' is up to date...
==> 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.20
default: VirtualBox Version: 5.1
==> default: Setting hostname...
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
default: /vagrant =>C:/Users/windows的账户名/Homestead
default: /home/vagrant/Code => D:/随便/项目的目录 //当你没看到这条信息请返回你的Homestead.yaml设定
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> default: flag to force provisioning. Provisioners marked to run always will still run.

好了,这算启动成功了,但是配置成功了吗?还不能确定的,输入 vagrant ssh 登入homestead

C:\Users\windows的账户名\Homestead> vagrant ssh
Welcome to Ubuntu 16.04 LTS (GNU/Linux 4.4.0-22-generic x86_64)
*Documentation: https://help.ubuntu.com/
vagrant@homestead:~$ //当看到这个说明登入成功了
vagrant@homestead:~$ ls //查看下一级目录 ,有Code,可以安心
Code
vagrant@homestead:~$ cd Code
vagrant@homestead:~/Code$ ls //当看到king了,你可以彻底放心了,配置成功了
king

提醒 :如果你启动了 Homestead , 你发觉你的配置文件 Homestead.yaml :想要修改 , 可以的使用命令:vagrant up –provision ,此命令必须在Homestead 启动后使用,此命令作用为更新Homestead.yaml的修改
8·最后要在浏览器上显示你的网页你必须设定对应的hosts .
hosts文件所在在目录:C:\Windows\System32\drivers\etc\hosts 先hosts拖到桌面,然后修改成:

|# Copyright (c) 1993-2009 Microsoft Corp.
|#
|# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
|#
|# This file contains the mappings of IP addresses to host names. Each
|# entry should be kept on an individual line. The IP address should
|# be placed in the first column followed by the corresponding host name.
|# The IP address and the host name should be separated by at least one
|# space.
|#
|# Additionally, comments (such as these) may be inserted on individual
|# lines or following the machine name denoted by a ‘#’ symbol.
|#
|# For example:
|#
|# 102.54.94.97 rhino.acme.com # source server
|# 38.25.63.10 x.acme.com # x client host
|
|# localhost name resolution is handled within DNS itself.
|# 127.0.0.1 localhost
|# ::1 localhost
|
|192.168.10.10 aimiliya.local
|192.168.10.10 lamu.local
|192.168.10.10 leimu.local

然后把刚复制到桌面而且修改好的hosts文件的拖回C:\Windows\System32\drivers\etc\hosts覆盖.注意:直接修改是不行的