欢迎光临
我们一直在努力

homestead安装,可用版

对于初次安装homestead是个技术活,网上教程一堆,但基本没有谁能看着教程弄下来,因为教程里很多没写的太清楚!

要安装好homestead有8个步骤

第一步很关键,不能使用windows的CMD命令,切记!!!

  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:

    {
            "name": "laravel/homestead",
            "versions":
    [
        {
            "version": "0.5.0",
            "providers": [
                {
                  "name": "virtualbox",
                  "url": "D:/box/virtualbox.box"  //你下载的virtualbox.box在电脑系统上的位置
                }
            ]
        }
    ]
    }

     

    打开的 IDE (编译器) 先不要保存,点击开始菜单或 win 快捷键 , 在搜索栏处输入你的terminal ( 终端 ) , 点击鼠标右键以管理员身份运行,一般会跳转到 :

    C:\Users\windows的账户名>

     

    然后回到 IDE (编译器) 保文件到C:\Users\windows的账户名这个目录下 , 并且命名为 a.json , 然后再回到terminal ( 终端 ) 输入一下代码 :

    C:\Users\windows的账户名> vagrant box add a.json

     

    C:\Users\windows的账户名> vagrant box add a.json 
    ==> box: Loading metadata for box 'a.json'
    box: URL: file://C:/Users/windows的账户名/a.json
    ==> box: Adding box 'laravel/homestead' (v0.5.0) 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' (v0.5.0) for 'virtualbox'!

     

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

    C:\Users\windows的账户名> ssh-keygen -t rsa -C "yenanzero@gamil.com"

     

    说明 : 这个命令是创建 Homestead 连接秘匙 , 因为我们是在本机上运行的所以不需要密码之类的 , 一直按回车就行

    C:\Users\windows的账户名> ssh-keygen -t rsa -C "yenanzero@gamil.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: E:/laragon/www                //这个是你的项目的地址,例如E:/laragon/www
    |      to: /home/vagrant/Code  //这个是homestead系统的地址 2
    |                                             //其实这就是windows和hometead两个系统共享一个文件夹,难懂一点的话叫||映射
    |
    |sites:    //__这个是你的项目
    |    - map: homestead.app  这个是你项目要设定在你的浏览器上的地址 //需要设定C host文件 
    |      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

     

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

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

 

赞(0)
版权归原作者所有,如有侵权请告知。达维营-前端网 » homestead安装,可用版

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址