1、先安装vagrant和 VirtualBox、git、composer
1.1、Virtualbox:/
1.2、Vagrant://
1.3、GIT:/download/win
1.4、composer:/download/
2、安装Homestead
2.1、添加Homestead Vagrant Box 到 Vagrant
2.1.1、在线安装 Laravel homestead
vagrant box add laravel/homestead
运行命令后会见如下:
选择 3 virtualbox
-
vagrant box add laravel/homestead
-
==> box: Loading metadata for box 'laravel/homestead'
-
box: URL: /laravel/homestead
-
This box can work with multiple providers! The providers that it
-
can work with are listed below. Please review the list and choose
-
the provider you will be working with.
-
-
1) hyperv
-
2) parallels
-
3) virtualbox
-
4) vmware_desktop
-
-
Enter your choice: 3
-
==> box: Adding box 'laravel/homestead' (v5.1.0) for provider: virtualbox
-
box: Downloading: /laravel/boxes/homestead/versions/5.1.0/providers/
-
box: Progress: 0% (Rate: 30987/s, Estimated time remaining: 21:48:20)^C==> box: Waiting for cleanup before exiting...
-
==> box: Box download was interrupted. Exiting.
由于国内下载速度很慢,推荐大家都直接使用本地 box 的方式安装 Laravel homestead
2.1.2、本地安装 Laravel homestead
Laravel homestead 地址:/boxes/search
-
vagrant box add laravel/homestead /Users/user/Downloads/ #存放的位置
-
-
vagrant box list
-
laravel/homestead (virtualbox, 0)
这种方式安装 vagrant up 启动时,会出错 vagrant box list 中显示为 0
解决办法:
在 Homestead\scripts\ 文件夹中,打开 文件
把
.box_version = settings["version"] ||= ">= 5.0.0"
改为
.box_version = settings["version"] ||= ">= 0"
2.1.3、另外一种离线安装方式
新建文件,把它放到下载好的文件目录下
内容如下:
-
{
-
"name": "laravel/homestead",
-
"versions": [{
-
"version": "9.7.2",
-
"providers": [{
-
"name": "virtualbox",
-
"url": "file://D:/laravelent/Vagrant/virtualbox-9.7."
-
}]
-
}]
-
}
-
vagrant box add
-
-
vagrant box list
-
laravel/homestead (virtualbox, 9.7.2)
3、克隆代码到宿主机上以安装 Homestead。推荐将代码克隆到「home」目录下的 Homestead 文件夹中,这样,Homestead box 就可以作为你的所有 Laravel 项目的主机:
git clone /laravel/ ~/Homestead
4、由于 Homestead 的 master 分支并不总是稳定的,可以在 GitHub Release Page 找到最新的稳定版本。或者,可以 checkout 最新稳定版本中的 release 分支:
-
cd ~/Homestead
-
-
git checkout release
5、一旦你克隆了 Homestead 仓库,可以运行 bash 命令以创建 配置文件。 将会置于 Homestead 目录中:
bash
6、配置秘钥(如果已经配置跳过)
-
cd ~/.ssh
-
ls
7、查看是否存在id_rsa和id_rsa.pub连个文件,如果有就不用,再生产,如果没有执行如下命令
-
ssh-keygen -t rsa -C "you@
-
私钥秘钥配置还有不明白可以查看:/woqianduo/article/details/81074184
8、配置
-
---
-
ip: "192.168.10.10"
-
memory: 2048
-
cpus: 2
-
provider: virtualbox
-
-
authorize: ~/.ssh/id_rsa.pub
-
-
keys:
-
- ~/.ssh/id_rsa
-
-
folders:
-
- map: F:/code #本地文件映射
-
to: /home/vagrant/code #虚拟机文件映射
-
-
sites:
-
- map: homestead.test
-
to: /home/vagrant/code/public
-
-
- map: blog.test
-
to: /home/vagrant/code/blog/public
-
-
databases:
-
- homestead
-
- blog
-
-
features:
-
- mysql: false
-
- mariadb: false
-
- postgresql: false
-
- ohmyzsh: false
-
- webdriver: false
-
-
# ports:
-
# - send: 50000
-
# to: 5000
-
# - send: 7777
-
# to: 777
-
# protocol: udp
9、主机名解析
在 Mac 和 Linux 上,其位于 /etc/hosts 。在 Windows 上,其位于 C:\Windows\System32\drivers\etc\hosts 。添加到 hosts 文件中的记录如下:
192.168.10.10 blog.test
10、 启动虚拟机
vagrant up
11、进入虚拟机
vagrant ssh