您的位置:首页 > 其它

windows10 安装homestead简单记录

2017-09-12 15:49 190 查看
国内windows安装homestead的教程几乎没有成功的。

自己在安装过程中不断的掉坑,不断地爆粗口,不断地放弃,不断的拾起,估计历经一周的时间总算成功。

首先有些坑必须采用特定的版本,本人成功搭配的组合是VirtualBox 5.1.14 (released
January 17th 2017)(必须)

下载地址:https://www.virtualbox.org/wiki/Download_Old_Builds_5_1

 Vagrant (2.0.0) Windows64位

下载地址: https://www.vagrantup.com/downloads.html

homestead (v3.0.0)下载地址 https://app.vagrantup.com/laravel/boxes/homestead

注意:必须用这三个版本才能保证少采坑,及成功率。

对于Git
Bash中输入
vagrant box add laravel/homestead
后自动下载的地址,劝你要是在祖国怀抱的话尝试都不用尝试了,果断用
https://app.vagrantup.com/laravel/boxes/homestead 下载homestead (v3.0.0),将下载的文件(hc-download)重命名为homestead.box(前缀不重要,但是一定要加上.box后缀)。

接下来打开Git Bash,输入
$ vagrant box add laravel/homestead file:///c:/users/MyUserName/downloads/homestead.box
1

其中请用你系统的用户名替换MyUserName,用自己的文件下载路径替换/downloads/homestead.box。然后等待添加完成。 



完成后,你会发现自己的用户文件夹里多出了一个.vagrant.d的文件夹(C:\Users\MyUserName.vagrant.d)。

接下来,非常重要的一个步骤:

我们打开这个文件夹,找到以下路径:
C:\Users\MyUserName\.vagrant.d\boxes\laravel-VAGRANTSLASH-homestead
1

在该文件夹下新建一个叫metadata_url的文件: 



文件的内容里,添加以下链接:
https://atlas.hashicorp.com/laravel/homestead
1



注意,不要留任何空白字符,保存文件。

同时将里面的0文件夹修改名称为3.0.0

完成之后,我们就可以开始配置Homestead了。

在Git Bash里输入
$ git clone https://github.com/laravel/homestead.git ~/Homestead
1



下载好了Homestead之后,我们就可以建立Homestead.yaml配置文件了:
Git Bash

# 先cd到刚才下载的Homestead文件夹
$ cd ~/Homestead

# 开始初始化Homestead
$ bash init.sh
1
2
3
4
5
6
7



然后在~/Homestead文件夹中,我们可以看到多出了一个叫Homestead.yaml的文件。使用notepad++打开它,可以看到内容如下:
---
ip: "192.168.10.10"
memory: 2048
cpus: 1
provider: virtualbox

authorize: ~/.ssh/id_rsa.pub

keys:
- ~/.ssh/id_rsa

folders:
- map: ~/Code
to: /home/vagrant/Code

sites:
- map: homestead.app
to: /home/vagrant/Code/laravel/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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

我们一条一条来配置。 

首先我们需要建立SSH Key并且填入路径。在Git Bash中,输入:
$ ssh-keygen -t rsa
1



完成后,我们会在用户根目录下看到一个.ssh文件夹,里面分别有
id_rsa.pub
id_rsa
1
2

两个文件,分别对应配置文件中
authorize: ~/.ssh/id_rsa.pub

keys:
- ~/.ssh/id_rsa
1
2
3
4
5

接下来我们看到这两段配置
folders:
- map: ~/Code
to: /home/vagrant/Code

sites:
- map: homestead.app
to: /home/vagrant/Code/laravel/public
1
2
3
4
5
6
7

其中folders中,将map后面的文件夹(即~/Code)映射到Homestead中的/home/vagrant/Code。这就像我们常见到的和虚拟机中系统共享文件夹类似,我们把本机的~/Code文件夹分享给Homestead,所以我们可以很方便地使用自己喜欢的IDE(比如PhpStorm)进行开发,在~/Code中所进行的修改会如实反应在Homestead对应的文件夹中。

在sites中,我们定义了homestead.app指向/home/vagrant/Code/laravel/public这个文件夹,即Laravel项目的public文件夹。这样在浏览器中输入homestead.app,我们就可以直接看到项目主页了。

注意:以上的文件夹及映射是可以根据用户喜好更改的,比如我喜欢把我的开发文件夹叫做WebDev,在里面我新建了一个叫teahouse的项目,那么以上的配置,我就可以做出相应修改:
folders:
- map: ~/Webdev
to: /home/vagrant/Webdev

sites:
- map: teahouse.app
to: /home/vagrant/Webdev/teahouse/public
1
2
3
4
5
6
7

是不是很方便呢?

下一步我们要在hosts文件中添加一行:
192.168.10.10 homestead.app
1

Windows的hosts文件在以下路径:
C:\Windows\System32\drivers\etc\
1

用notepad++打开即可:
# 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

# 添加上这一行,将homestead.app替换成自己的项目名称
192.168.10.10 homestead.app
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

接下来我们来看
databases:
- homestead
1
2

在这里,我们每添加一个数据库名字,那么Homestead将会自动创建一个该名字的数据库来供我们操作。

在这里,我添加了一个新的数据库:
databases:
- homestead
- teahouse
1
2
3

注意:不要使用tab来留空,否则会报错(可以是用空格对齐)。

默认的MySQL服务器用户名为homestead,密码是secret。

将Homestead.yaml保存,我们就可以启动Vagrant了!激动吗?

以管理员的身份打开Git Bash,输入
Git Bash

$ cd ~/Homestead
$ vagrant up
1
2
3
4



我们会看到,Vagrant已经顺利运行了! 

输入homestead.app能够看到你的网站了。

对于数据库连接

使用信息192.168.10.10

用户名homestead

密码secret

端口号:3306(注意不是33060,至于为什么不是,我也不知道,你可以试试到底哪个好使)

ssh 连接

127.0.0.1:2222

用户名:vagrant

密码vagrant

使用sudo改成root用户,其它还有些内容,做完最近的项目再仔细整理

参考文章:
http://blog.csdn.net/lgyaxx/article/details/60870819  千挑万选还算靠谱的文章
https://github.com/laravel/homestead/issues/510 告诉我两种错误,


Unable to mount shared folders on new installation

和 no input file specified直接换virtualbox到我刚才指定的版本就好了。

注意事项



folders中map 斜线的方向,直接把Windows地址栏中站过去就好了,这是个坑

修改homestead.yaml配置文件一定在homestead文件夹中下用管理员身份运行bash here.

使用vagrant up --provision

已经运行的情况是可以直接用vagrant provision.

关闭使用vagrant halt

销毁使用vagrant destroy

homestead命令根本用不到

vagrantfile默认就好,不用修改。

如果用的homestead.rb,地址C:\Users\admin\Homestead\scripts,

干货,转载请注明原文链接。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: