如何在 Windows 上安装 Laravel Homestead

:cn: 要安装好honmestead有8个步骤

  1. 首先你首先要确定你有个好的 terminal [ 终端:cmder 或 Git 的git bash ] . 注意windows的cmd不能用

  2. 下载和安装 [ virtualbox ] 和 [ vagrant ] 前者为系统装载用的,后者为系统控制用的

  3. 如果你要使用 homestead 就必须要有个virtualbox.box的文件 ,官方 Laravel 下载这个文件的这个命令为

    vagrant box add laravel/homestead

    但是因为中国的对外国网络资源的限制,你要下载这个文件可能会需要不少的时间
    因此 , 在这我们拥有两个选择的余地

    • 选择一 : 当你使用官方下载命令时,你的终端会显示这个文件的源地址复制,然后按 ctrl +c 退出,然后用的喜欢的下载软件下载.
    • 选择二 : phphub上的 virtualbox.box
  4. 好了 , 现在我假设你已经拥有这个文件,现在来用我们的方法添加virtualbox.box .
    打开你的ide(代码编译器) ,一般为 Sublime Text 和 Atom ,为何要提编译器呢 , 因为下面的步骤可能会需要其中一个的编译器 , 创建一个名为a.json的文件 , 输入以下内容 :arrow_down:

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

  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覆盖.注意:直接修改是不行的


    好了,这就是最后的配置了,请开心的进行Laravel开发吧 !!!

新增问题 1 :
关于vagrant up停顿在以下的画面 :

Timed out while waiting for the machine to boot. This means that
Vagrant was unable to communicate with the guest machine within
the configured ("config.vm.boot_timeout" value) time period.
If you look above, you should be able to see the error(s) that
Vagrant had when attempting to connect to the machine. These errors
are usually good hints as to what may be wrong.
If you're using a custom box, make sure that networking is properly
working and you're able to connect to the machine. It is a common
problem that networking isn't setup properly in these boxes.
Verify that authentication configurations are also setup properly,
as well.
If the box appears to be booting properly, you may want to increase
the timeout ("config.vm.boot_timeout") value.
请参考链接

留言 :
对于尝试成功的朋友在下面回复留言成功,以便更多的网友知道此方法,
不成功的请用 markdown
 贴出错误的地方

要转载的话来源标记为PHPHub就行了,这个是给PHPHub的礼物了:relaxed:
实在有不明白的此帖隐藏有我邮箱,发信件到我邮箱就行了 .
本帖已被设为精华帖!
本帖由 Summer 于 7年前 加精
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
讨论数量: 71
Summer

内容挺棒 :+1: ,就是 Markdown 格式挺乱。。。

7年前 评论

难得有 windows 下的 homestead 详细教程。:+1:

7年前 评论

virtualbox 和 vagrant 都要求最新版吗?

7年前 评论

@oakchen 都可以的,不过最新版可能会好点!至于好在哪里我就可能回答不了你了!

7年前 评论

@Summer 我挺喜欢你的网站的,不过我想summer主题是不是应该分类清楚一点,我最近电脑重装windows ,homestead重新安装,老早忘了怎么装了,所以进phphub找帖子,我发现很多帖子都不成功的,主要还是区别在mac和windows,所以才写的这么详细,我想应该直接在http://learnku.com/docs/laravel/5.1/homestead中直接标记mac和windows的安装是有区别的,比如有些人在mac中能开启nfs ,而windows中确是不支持!还有很多很多!主要还是分类的不清楚我觉得

7年前 评论
Summer

@ynanzero 你是在指标签类似的分类系统?

你可以把文章 Markdown 修整好,我在计划弄个 wiki 页面,到时候一起链接起来。

7年前 评论

@Summer 这样格式行吗?

7年前 评论
Summer

@ynanzero 花了好久调的吧?太赞了 :100:

7年前 评论
Summer

已经加到 wiki 中

7年前 评论
OMGZui

谢谢分享,已成功

7年前 评论

按步骤配置完了,也起来了。但是共享目录一直没生效,这是为什么。配置也没错

7年前 评论

@wind 如果不介意请告诉我你的系统,还有 homestead.yaml 的配置 , 如果你对markdown不熟悉可以截张图片发上来给我看看 .

7年前 评论

@ynanzero

win10、virtualBox 5.0、vagrant 1.8.1,vbox 0.4.4
步骤完全按照上面说的一步步做,homestead.yaml 配置也一样,就是起来后ssh登录,发现没有宿主机共享的目录 T T

7年前 评论

@wind 我知道哪里的问题了,是我错了,你必须在C:\Users\windows的账户名\Homestead>vagrant up,抱歉!

7年前 评论

@ynanzero .......................... 纳尼。。 好吧,我试试

7年前 评论

@wind 是否成功了呢?

7年前 评论

@ynanzero 刚box remove了- -。得重装。又发现蛋疼的网络慢的要死,得等等了, 好了给你回复。~

7年前 评论

@wind 抱歉因为文章修改了格式,可能有些地方我没有发觉的,不小删除了,我以修改!

7年前 评论

@wind 还有你 vagrant box add a.json 先加一个版本其他的不要加进去

7年前 评论

@wind 今天又试了一下, 完美~~ 感谢。

7年前 评论

@wind 你是否已经启动成功了一次?

7年前 评论

@wind 重启Homestead, 不行再检查你的电脑是否支持 VT-x,检查之后我们继续,还有能否告诉我,你能持续在线的时间,我能更好的帮助你

7年前 评论

@Summer summer,你是否拥有一部windows电脑,关于 VT-x,我觉得这个文章篇幅肯定写不下了,你能否重新开篇文章我加个连接,还有就是关于VT-x,让我来叙述可能会不太清楚!

7年前 评论
Summer

@ynanzero 我用的是 Mac :cry:

7年前 评论

@Summer 我两种都有,不过mac是2011年的air,用起来现在最新版windows还没有mac的11年好,很后悔当初就因为差几千块钱买了windows,虽然性能好了,做开发始终不如mac,我现在有个问题就是我发觉windows安装homestead的不成功的原因还挺多,我是否只是给个链接让他们看英文还是详细写出教程,这个问题给我带来了困扰,最近发这个贴我有点困扰,因为写的详细当别人不成功时似乎是自己造成的错误。现在这个帖子好像变成了我责任一般,你说我该怎么办?

7年前 评论
Summer

@ynanzero 不要当成责任哈,心情好就帮别人解答,心情不好就不要管,谁也没有义务做这种事情,我觉得即使是加个链接,也都很了不起了。

维护这些东西挺难的,并且很多时候吃力不讨好。

在我看来,你已经做的足够好了,并且我觉得很多社区里的同学都会和我一样觉得。

7年前 评论
Summer

@ynanzero Mac 绝逼要买 15' 高配的 :stuck_out_tongue: ,我第一台是信用卡透支买的

7年前 评论

@ynanzero 已经都OK了, 关于 VT-x 开不起来,我换了台机器(家里),bios里已经开了。但是无论怎么重启都是没用,拿工具测了下 VT-x就是未启用, 后面用了个很粗暴的方法解决了。 就是bios开启,f10保存退出,再进去bios,直接按电源关机再进系统,一切OK。

我也是醉了。。

7年前 评论

操作系统:Windows Server 2008 R2 Enterprise 64bit

VirtualBox的版本:VirtualBox-5.1.4-110228-Win

Vagrant的版本:vagrant_1.8.5

下载的Box是从以下百度云下载的,用了迅雷和百度云软件下载
https://pan.baidu.com/s/1hrN55w4

以下的两个版本都试过了:

homestead-virtualbox-0.2.7

homestead-virtualbox-0.4.4

总是出错,不知道是什么原因,有点崩溃

file

7年前 评论

@yemao 为什么不创建json用我的方法?

7年前 评论

@yemao 在你这个报错误的应该是box的问题,可是我也不能百分之一百确认你的box坏了,你用的我的方法加创建json,add json,然后给我看看终端,我才能回答你,可以吗?

7年前 评论

谢谢,我用过json方法了也是一样。我怀疑跟我的服务器系统有关系。因为不管怎样来加都是报an error accurr....

(我在我本机笔记本试过box虽然也没成功,但不是在这一步报错)

以下是a.json内容

file

box的问题,我按照https://phphub.org/topics/2090

这里的看了文件的CheckSum是对得上的,不知道这样能不能算是不会坏。

file

7年前 评论

@ynanzero

Vagrant 换成了1.7.4的版本,就好了。。此处有泪流满面->>:joy_cat:

file

7年前 评论

@ynanzero 按照您的教程配置成功了。但是在配置多个域名的时候,总是执行一个同一个应用。我的homestead.yaml配置如下:
file

hosts文件配置如下:

file

当我访问
http://homestead.app

file

访问http://laravel.app ,也执行同一个应用

file

7年前 评论

补充一下:vagrant的版本为1.7.4,virtualbox的版本最高为5.0。(5.1的不行)。virtualbox.box用0.5.0的时候,在vagrant up的时候出现:

the following ssh command responded with a non-zero exit status
/sbin/ifdown eth1 2> /dev/null

直接vagrant ssh无法登录,换成其他ssh客户端可登录,但是无Code目录,且虚拟机与本机之间共享的目录无法同步。

搜了网上的几个方法都没有解决

1、修改homestead.rb

inline = "echo \"$1\" > /home/vagrant/.ssh/\"$2\" && chmod 600 /home/vagrant/.ssh/\"$2\""

2、sudoers增加以下

vagrant ALL=(ALL) NOPASSWD:ALL
Defaults:vagrant !requiretty

3、执行以下删除

sudo rm -f /etc/udev/rules.d/70-persistent-net.rules

最后virtualbox.box换成了0.4.4,就OK了

另外在Homestead初始化的时候提示vagrant版本需要大于等于1.8.4,我直接在Homestead目录下的vagrantfile修改大于等于1.7.4初始化成功。不知后续有没问题,目前未发现。

7年前 评论

@fengchunlong 嗯~如果你还没有得到解决,你是否第一次配置成功了,然后又添加的多域名?
如果是 ,试试vagrant up后vagrant up --provision,还不行我们再继续探讨

7年前 评论

@yemao 嗯嗯!就你这个问题我也去了解了一下,确实时需要相对应的版本才可以安装在windows server上,如果你有博客或者你开篇文章我转个链接吧!你写写具体在windows server 上操作的过程吧!毕竟可能有人与你有同样问题 . .....

7年前 评论

@ynanzero 我这边测试下来发现2点:

  • 如果不配置 site, homestead 会默认使用 hhvm 作为php引擎
  • yaml 中的配置需要 vagrant up --provision 才能生效, 不过对我的设置有好处, 我这边喜欢自己配置 nginx, 这样就不会被 vagrant up 给重设掉
7年前 评论

按照上面的方法,到执行 vagrant up时遇到一个问题,麻烦大神看下!
以下为报错信息:

There was an error while executing VBoxManage, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.

Command: ["startvm", "276526ae-6990-49f9-bf08-b713c1f577aa", "--type", "headless"]

Stderr: VBoxManage.exe: error: The virtual machine 'homestead-7' has terminated unexpectedly during startup with exit code 1 >(0x1). More details may be available in 'C:\Users\sc\VirtualBox VMs\homestead-7\Logs\VBoxHardening.log'
VBoxManage.exe: error: Details: code E_FAIL (0x80004005), component MachineWrap, interface IMachine

7年前 评论
siyecao

大神 你上面截图| to: /home/vagrant/Code //这个是homestead系统的地址 2 这个地址是我用git clone homestead的路径吗?

7年前 评论

@suoak 请问你的问题解决了吗?我有一台电脑也遇到同样的问题。

7年前 评论

@ynanzero 你好,按照这些过程配置完成,vagrant ssh登陆之后在Homestead里面也能看到/home/vagrant/Code目录,但是本机在 ~/Code 建立的Laravel项目却没有同步过来(在Homestead的/home/vagrant/Code 下输入 ls 始终显示为空)请问这是为什么呢?

7年前 评论

@fengchunlong 你好,请问你的问题解决了吗?我也是遇到了同样的问题。win10系统。

7年前 评论

@凭栏 按楼主说的试一下

vagrant up

然后

vagrant up --provision
7年前 评论
gitxuzan

很棒

:smile::smile::smile::smile::smile::smile::smile::smile::smile::smile::smile::smile::smile::smile::smile::smile: smile::smile::smile::smile::smile:
数据库连接怎么配置?

6年前 评论

环境比代码难系列:sleeping:

6年前 评论

file
没有code文件 大哭 @ynanzero

6年前 评论

还有个奇怪的问题 第二次装的时候 运行bash init.sh 并没有在用户文件夹下新建.homestead文件夹呢 这个homestead门槛也太高了吧 哎。。。。。。。。@ynanzero

6年前 评论

file
请问一下这是什么原因呢?@ynanzero

6年前 评论

写技术文章就应该像你这样,点名要害,赞!

6年前 评论

homestead-7: Failed to restart php5.6-fpm.service: Unit php5.6-fpm.service not found.
homestead-7: Failed to restart php7.1-fpm.service: Unit php7.1-fpm.service not found.
The SSH command responded with a non-zero exit status. Vagrant
assumes that this means the command failed. The output for this command
should be in the log above. Please read the output to determine what
went wrong.

请问我在执行vagrant up 命令之后报出这样的错误,应该怎么办?

6年前 评论

@VShangxiao 你好,我和你遇到了相同的问题,cd Code 后 ls 没有接下来的目录了,你解决了吗
‘?’

6年前 评论

file
重装了一次,出现了这个问题,time out是怎么回事呢?

6年前 评论

@xingxiaoli

file
第一次vagrant up的时候会失败,因为virtualBox->设置->网络里,接入网线没有勾选。关闭homestead,将这个选项勾选上,再次启动就可以了。

6年前 评论

楼主,我遇到

file
上图的错误,请指点迷津

5年前 评论

第五步的时候是不是需要输入什么,好像没有写吧

5年前 评论

file
win10 安装出错了 提示 VirtualBox 创建文件失败

5年前 评论

file

vagrant up 时出现这个已经存在问题怎么解决?

5年前 评论

Windwos环境下,如果IP地址设置和主机的Ip地址在同一网关,那么就会报错。如果不是同一网关,那么就可以运行成功,这如何解决?

4年前 评论

我 vagrant up
的时候,总是报错内存不够,我想怎么样才能把 .vagrant.d移动到别的盘

file

4年前 评论

windows homestead启动后,下一步的开发laravel应该装在哪
不知道composer global require laravel/installer在homestead中执行,还是在windows执行
file

4年前 评论

请问大神,homestead建立后,laravel new 项目名后,出现异常[ErrorException] mkdir(): Not a directory,怎么解
file

4年前 评论

file

这是显示错误了???

3年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!