配置Homestead虚拟机
1. 下载安装virtualbox
下载页面:https://www.virtualbox.org/wiki/Downloads 下载地址:https://download.virtualbox.org/virtualbox/5.2.8/VirtualBox-5.2.8-121009-Win.exe
2. 下载安装vagrant
下载页面:https://www.vagrantup.com/downloads.html 下载地址:https://releases.hashicorp.com/vagrant/2.0.3/vagrant_2.0.3_x86_64.msi?_ga=2.196898604.1044287119.1522760150-1086744677.1522760150
3. 下载homestead镜像包
homestead主页:https://app.vagrantup.com/laravel/boxes/homestead(可以根据需要下载最新的包) 下载地址:https://atlas.hashicorp.com/laravel/boxes/homestead/versions/5.0.1/providers/virtualbox.box
4. 添加metadata.json文件
新建metadata.json文件,将medata.json文件与vritualbox放在同一目录
{ "name": "laravel/homestead", //盒子名称 "versions": [ { "version": "5.0.1", //版本号 "providers": [ { "name": "virtualbox", "url": "virtualbox.box" //盒子所在路径 } ] } ] }
5. metadata.json 与 下载的homestead放在同目录
在metadata.json目录下执行vagrant box add metadata.json命令
6. 安装Homestead
cd ~ git clone https://github.com/laravel/homestead.git Homestead cd Homestead git checkout v6.1.0(切换至最新分支) 运行 init.bat文件会生成一个Homestead.yaml文件 配置Homestead.yaml文件 --- ip: "192.168.0.176" memory: 2048 cpus: 1 provider: virtualbox authorize: ~/.ssh/id_rsa.pub keys: - ~/.ssh/id_rsa folders: - map: E:/code to: /home/vagrant/Code sites: - map: www.laravel.test to: /home/vagrant/Code/Laravel/public params: - key: APP_ENV value: dev databases: - homestead
7. 启动虚拟机
切换当前路径至Homestead目录下执行
vagrant up启动虚拟机
8. 连接虚拟机
vagrant ssh
9. 关闭虚拟机
vagrant halt
10. 连接数据库
homestead虚拟机中mysql数据库默认账号
用户名:homestead,
密码:secret mysql -uhomestead -psecret
11. 创建批处理脚本一键启动虚拟机
12. 创建批处理脚本,一键关闭虚拟机