根据官方文档翻译而来,涉及的主要内容是 virtualbox
安装 virtualbox,vagrant,git
https://www.virtualbox.org/wiki/Downloads
https://www.vagrantup.com/downloads.html
https://git-scm.com/download/win
git 初始化
git config --global user.name leonzai
git config --global user.email leonzai@aliyun.com
ssh-keygen -t rsa
添加 box
vagrant box add laravel/homestead
国内墙的厉害,下载下来再添加:
https://atlas.hashicorp.com/laravel/boxes/homestead/versions/版.本.号/providers/virtualbox.box重命名为 larabox
vagrant box add laravel/homestead ./larabox
克隆安装 Homestead
cd ~
git clone https://github.com/laravel/homestead.git Homestead
cd Homestead
git checkout v9.9.9 # https://github.com/laravel/homestead/releases
初始化 Homestead
bash init.sh
启动 vagrant
修改 homestead.rb
settings[“version”] ||= “>= 0”
找到 composer self-update 删除它
vagrant up
配置 Homestead
# 设置同步文件夹
folders:
- map: ~/code
to: /home/vagrant/code
# 当文件太多,或者多个项目适合,请将每个项目映射到各自的 vagrant 目录
folders:
- map: ~/code/project1
to: /home/vagrant/code/project1
- map: ~/code/project2
to: /home/vagrant/code/project2
# (windows 并不生效)开启 nfs,此时最好安装插件 [vagrant-bindfs](https://github.com/gael-ian/vagrant-bindfs) 它负责维护文件和目录的权限
folders:
- map: ~/code
to: /home/vagrant/code
type: "nfs"
配置站点
# 不要忘记添加本地的 dns,例如:192.168.10.10 homestead.com
sites:
- map: homestead.com
to: /home/vagrant/code/Laravel/public
删除 vagrant box
vagrant destroy --force
针对项目安装 Homestead
composer require laravel/homestead --dev
# 好处是,如果协同开发,只需要把 `Vagrantfile` 发给对方,对方 `make` 下,然后开启 `vagrant up` 就能有同样的配置和环境。
MariaDB 替换 Mysql
box: laravel/homestead
ip: "192.168.10.10"
memory: 2048
cpus: 4
provider: virtualbox
mariadb: true
别名
alias c='clear'
alias ..='cd ..'
# 使生效 `vagrant reload --provision`
连接 ssh
vagrant ssh
连接 数据库
本地连接 mysql 33060
重新加载 vagrant 配置
# 例如添加了一个站点,重新加载 vagrant 记得添加 dns
vagrant reload --provision
给 nginx 添加 fastcgi_param
sites:
- map: homestead.test
to: /home/vagrant/code/Laravel/public
params:
- key: FOO
value: BAR
配置 Cron
# 配合 artisan 命令 schedule:run 使用
sites:
- map: homestead.test
to: /home/vagrant/code/Laravel/public
schedule: true
端口转发
SSH: 2222 → Forwards To 22
ngrok UI: 4040 → Forwards To 4040
HTTP: 8000 → Forwards To 80
HTTPS: 44300 → Forwards To 443
MySQL: 33060 → Forwards To 3306
PostgreSQL: 54320 → Forwards To 5432
Mailhog: 8025 → Forwards To 8025
指定 php 版本,默认 7.2
sites:
- map: homestead.test
to: /home/vagrant/code/Laravel/public
php: "5.6"
更新 Homestead
vagrant box update
git pull origin master 或者 composer update