目录

安装 vagrant

mac 下,vagrant 桥接,选择 en0: 以太网”无法启动虚拟机解决方案 http://www.th7.cn/system/mac/201511/141081.shtml

以下方法根据 homestead,可供参考

  1. 下载安装 virtualbox 和 vagrant
  2. 安装 box
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
LiangXueFengdeiMac:test liutao$ vagrant box add homestead_0.4.4 ~/Work/Vagrant/box/
.DS_Store       virtualbox.box
LiangXueFengdeiMac:test liutao$ vagrant box add homestead_0.4.4 ~/Work/Vagrant/box/virtualbox.box
==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box 'homestead_0.4.4' (v0) for provider:
    box: Unpacking necessary files from: file:///Users/liutao/Work/Vagrant/box/virtualbox.box
==> box: Successfully added box 'homestead_0.4.4' (v0) for 'virtualbox'!

#在指定目录下安装。(全局安装会在用户目录下)
LiangXueFengdeiMac:test liutao$ cd ~/Work/Vagrant/CRM/

LiangXueFengdeiMac:CRM liutao$ composer require laravel/homestead --dev


LiangXueFengdeiMac:CRM liutao$ vagrant init
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.

#执行此命令,会生成 Vagrantfile 和Homestead.yaml 文件
LiangXueFengdeiMac:CRM liutao$ php vendor/bin/homestead make
Homestead Installed!

Homestead.yaml 文件默认如下:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
---
ip: "192.168.10.10"
memory: 2048
cpus: 1
hostname: crm
name: crm
provider: virtualbox

authorize: ~/.ssh/id_rsa.pub

keys:
    - ~/.ssh/id_rsa

folders:
    - map: "/Users/liutao/Work/Vagrant/CRM"
      to: "/home/vagrant/crm"

sites:
    - map: homestead.app
      to: "/home/vagrant/crm/public"

databases:
    - homestead

此文件可根据需要更改映射的 folders

在 hosts 文件中添加如下内容 192.168.10.10 homestead.app

vagrant up

* Users/liutao/Work/Vagrant/CRM/vendor/laravel/homestead/scripts/homestead.rb:116:in `read’: No such file or directory @ rb_sysopen - /Users/liutao.ssh/id_rsa (Errno::ENOENT) *

1
ssh-keygen

Homestead\scripts\文件夹中,打开 homestead.rb 文件

config.vm.box_version = settings[“version”] ||= “>= 0.4.0” 改为 config.vm.box_version = settings[“version”] ||= “>= 0”

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
Vagrant was unable to mount VirtualBox shared folders. This is usually
because the filesystem "vboxsf" is not available. This filesystem is
made available via the VirtualBox Guest Additions and kernel module.
Please verify that these guest additions are properly installed in the
guest. This is not a bug in Vagrant and is usually caused by a faulty
Vagrant box. For context, the command attempted was:

mount -t vboxsf -o uid=900,gid=900 vagrant /vagrant

The error output from the command was:

/sbin/mount.vboxsf: mounting failed with the error: No such device

解决办法: https://segmentfault.com/a/1190000002869922