Homestead 的安装踩坑记
https://learnku.com/docs/laravel-development-environment/7.x/development-environment-windows/8444
https://learnku.com/laravel/wikis/25528
准备材料:
- 虚拟机
Virtual Box 5.2 https://www.virtualbox.org/wiki/Downloads - 是一个在单一工作流中建立和管理虚拟机环境的工具
Vagrant https://www.vagrantup.com/downloads.html - Git 工具
- 安装 laravel/homestead
- 命令安装 vagrant box add laravel/homestead,国外网站,较慢
2.手动下载 https://vagrantcloud.com/laravel/boxes/homestead/versions/5.2.0/providers/virtualbox.box ,建议手动下载文件
5.homestead 包
6.Laravel 5.6 的包,composer(composer create-project --prefer-dist laravel/laravel blog 5.6.*) 后者 一键安装包 http://laravelacademy.org/resources-download
开始安装:
第一步 :
安装 Virtual Box5.2 程序,安装Vagrant
第二步:下载Homestead 组件包
在命令行界面,进入用户目录, cd ~
在用户目录执行: git clone https://github.com/laravel/homestead.git Homestead
初始化 Homestead,
cd Homestead
bash init.sh
或者进入 Homestead 目录,双击 init.bat 文件
在 Homestead 目录下,编辑 Homestead.yaml 文件
虚拟机IP
ip: "192.168.10.10"
虚拟机内存大小
memory: 2048
虚拟机cpu数量
cpus: 1
提供虚拟机类型
provider: virtualbox
公钥SSH KEY
authorize: C:/Users/hhh/.ssh/id_rsa.pub
私钥SSH KEY
keys:
- C:/Users/hhh/.ssh/id_rsa
共享文件夹,k可以 写多个map ,多虚拟主机
folders:
- map: D:/Xampp/htdocs/blog #自己电脑上的项目路径
to: /home/vagrant/Code #映射到虚拟机中的路径 - map: D:/Xampp/htdocs/blog3 #自己电脑上的项目路径
to: /home/vagrant/Code3 #映射到虚拟机中的路径
站点配置web服务器配置
sites:
- map: test.com #域名
to: /home/vagrant/Code/blog3/public #域名的映射地址 - map: test3.com #域名
to: /home/vagrant/Code/blog3/public #域名的映射地址
数据库配置
databases:
- homestead #在这里,我们每添加一个数据库名字,那么Homestead将会自动创建一个该名字的数据库来供我们操作。
默认的MySQL服务器用户名为homestead,密码是secret。
修改后,保存
在修改本机系统的 host 文件(C:\Windows\System32\drivers\etc)
添加
第三步:
生成秘钥
ssh-keygen -t rsa -C "youremail@example.com"
第四步:
加载 laravel/homestead 下载下来的.box 文件
vagrant box add laravel/homestead e:/virtualbox.box
完成之后,你会发现在自己 用户目录下生成了一个 .vagrant.d 的文件件 (C:\Users\hhh.vagrant.d)
第五步:
启动 vagrant
进入 Homesread 目录’
hhh@Anter-PC MINGW64 ~/Homestead ((v7.3.0))
$ vagrant up
会出现错误:
Bringing machine 'homestead-7' up with 'virtualbox' provider...
==> homestead-7: Box 'laravel/homestead' could not be found. Attempting to find and install...
提示找不到 laravel/homestead ,这是因为 手动安装homestead,在用户根目录下得到了C:\Users\Administrator.vagrant.d\boxes\laravel-VAGRANTSLASH-homestead\0
修改C:\Users\Administrator\Homestead\scripts下的homestead.rb文件
将 config.vm.box_version = settings["version"] ||= ">=5.2.0" 改为 config.vm.box_version = settings["version"] ||= ">=0"
再次执行 vagrant up ,则会成功进入
$ vagrant up
Bringing machine 'homestead-7' up with 'virtualbox' provider...
==> homestead-7: Clearing any previously set forwarded ports...
==> homestead-7: Fixed port collision for 80 => 8000. Now on port 2200.
==> homestead-7: Clearing any previously set network interfaces...
==> homestead-7: Preparing network interfaces based on configuration...
homestead-7: Adapter 1: nat
homestead-7: Adapter 2: hostonly
==> homestead-7: Forwarding ports...
homestead-7: 80 (guest) => 2200 (host) (adapter 1)
homestead-7: 443 (guest) => 44300 (host) (adapter 1)
homestead-7: 3306 (guest) => 33060 (host) (adapter 1)
homestead-7: 4040 (guest) => 4040 (host) (adapter 1)
homestead-7: 5432 (guest) => 54320 (host) (adapter 1)
homestead-7: 8025 (guest) => 8025 (host) (adapter 1)
homestead-7: 27017 (guest) => 27017 (host) (adapter 1)
homestead-7: 22 (guest) => 2222 (host) (adapter 1)
==> homestead-7: Running 'pre-boot' VM customizations...
==> homestead-7: Booting VM...
==> homestead-7: Waiting for machine to boot. This may take a few minutes...
homestead-7: SSH address: 127.0.0.1:2222
homestead-7: SSH username: vagrant
homestead-7: SSH auth method: private key
如果修改了 Homestead.yaml 文件,name执行 vagrant up --provision 命令,重新载入配置文件,并生效
在 Homestead 目录下 执行 vagrant ssh 命令,链接 虚拟机,
hhh@Anter-PC MINGW64 ~/Homestead ((v7.3.0))
$ vagrant ssh
Welcome to Ubuntu 16.04.4 LTS (GNU/Linux 4.4.0-116-generic x86_64)
- Documentation: https://help.ubuntu.com
- Management: https://landscape.canonical.com
- Support: https://ubuntu.com/advantage
0 packages can be updated.
0 updates are security updates.
vagrant@homestead:~ls code go1.10.linux-amd64.tar.gz vagrant@homestead:~ cd code/
vagrant@homestead:~/codels laravel56 vagrant@homestead:~/code cd laravel56/
最后一步:
浏览器访问,刚刚自己设置的 虚拟域名, test.com
题外:
可以使用本机的数据库管理工具,链接虚拟机里面的数据库,端口要写成 上面提示的,33060
数据库默认账号:homestead 密码:secret
作者:peijiyang
链接:https://www.jianshu.com/p/176294a119a8
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。