不知道啥原因本机的Homestead环境各种报错无法使用,于是就重新安装。在使用
vagrant box add laravel/Homestead
命令安装,也遇到各种奇葩状况,结果折腾了一天,最后各种谷歌,才用离线的方法安装成功
1.安装virtualbox、vagrant和git。一般选择最新版本的软件即可.
注意:
1.virtualbox版本5.0.28有问题,我用的老版本5.0.10。
2.请将virtualbox进行如下图所示进行操作,如果不进行此操作,会卡在
default: SSH auth method: private key
这里。
==> 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: bridged
==> default: Forwarding ports...
default: 22 => 2222 (adapter 1)
==> 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
2.添加homestead镜像
1.如果直接运行官方命令vagrant box add laravel/Homestead
,会由于网速原因出现各种问题,如果网络好请直接运行该命令。
2.如果网络状况不好,可以在http://pan.baidu.com/s/1hrN55w4
下载。
2.1 建立metadata.json文件,将该文件放在和下载BOX同目录
{
"name": "laravel/homestead",
"versions": [{
"version": "0.6.0",//BOX版本号
"providers": [{
"name": "virtualbox",
"url": "file:///Users/Dev/Box/Homestead/homestead-virtualbox-0.6.0.box" //BOX路径
}]
}]
}
2.2 终端进入virtualbox.box所在目录,使用vagrant box add metadata.json
进行安装
3.克隆和修改homestead配置文件。在git bash根目录下git clone https://github.com/laravel/homestead.git Homestead
1.生成Homestead.yaml文件。切换至Homestead目录cd Homestead
,运行命令sh init.sh
生成Homestead.yaml
文件,文件位于根目录.homestead
下,文件内容如下:
---
ip: "2.2.2.2"
memory: 2048
cpus: 1
provider: virtualbox
authorize: ~/.ssh/id_rsa.pub
keys:
- ~/.ssh/id_rsa
folders:
- map: /Documents/Dev/Homestead/Code/ //本机目录
to: /home/vagrant/Code/ //虚拟机映射目录
type: "nfs" //最好加这个,我之前没加,打开运行页面很慢
sites:
- map: homestead.app
to: /home/vagrant/Code/
databases:
- homestead
# blackfire:
# - id: foo
# token: bar
# client-id: foo
# client-token: bar
# ports:
# - send: 50000
# to: 5000
# - send: 7777
# to: 777
# protocol: udp
2.修改homestead.rb
文件,将config.vm.box_version = settings["version"] ||= ">= 0.4.4"
修改为config.vm.box_version = settings["version"] ||= ">= 0"
注意:
请注意PHP的版本,由于最新的homestead配置文件PHP版本为7.1,可能我们下载BOX的版本为7.0,所以需要将script目录中所有文件的php7.1-fpm修改为php7.0-fpm。如果PHP版本为7.1,则无需修改。
├── blackfire.sh
├── clear-nginx.sh
├── clear-variables.sh
├── create-mysql.sh
├── create-postgres.sh
├── cron-schedule.sh
├── homestead.rb
├── install-maria.sh
├── serve-apache.sh
├── serve-hhvm.sh
├── serve-laravel.sh
├── serve-proxy.sh
└── serve-symfony2.sh
3.修改host文件
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
2.2.2.2 homestead.app
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。