homestead
Laravel Homestead是一個官方預封裝的Vagrant“箱子”
內置 Nginx、PHP 5.6、MySQL、Postgres、Redis、Memcached 等常用軟件
安裝
安裝VirtualBox 和 Vagrant
添加 laravel/homestead
盒子
vagrant box add laravel/homestead
克隆 homestead 配置
git 克隆
git clone https://github.com/laravel/homestead.git Homestead
composer 安裝方式
composer global require "laravel/homestead=~2.0"
~/.composer/vendor/bin
目錄添加到 PATH 環境變量中后,可執行homestead
編輯Homestead.yaml配置文件
生成 Homestead.yaml 配置文件
homestead方式 homestead init
shell方式 bash init.sh
編輯 Homestead.yaml
homestead方式 homestead edit
直接編輯 vim ~/.homestead/Homestead.yaml
配置與操作
配置詳解
ip: "192.168.10.10"
memory: 512
cpus: 1
provider: virtualbox # 需要使用的 Vagrant prodiver:virtualbox還是vmware_fusion
authorize: ~/.ssh/id_rsa.pub # 公鑰路徑
keys:
- ~/.ssh/id_rsa # 秘鑰路徑
folders: # 共享目錄
- map: ~/Code
to: /home/vagrant/Code
sites: # 配置站點
- map: homestead.app
to: /home/vagrant/Code/Laravel/public
databases:
- homestead
variables:
- key: 'APP_ENV'
value: 'local'
- key: 'APP_DEBUG'
value: 'true'
# blackfire: # Blackfire Profiler分析工具
# - id: foo
# token: bar
# client-id: foo
# client-token: bar
# ports: # 自定義端口轉發
# - send: 93000
# to: 9300
# - send: 7777
# to: 777
# protocol: udp
虛擬機操作
Homestead
目錄下
- 開機: vagrant up
- 關機: vagrant halt
- 銷毀: vagrant destroy --force
- 登錄: vagrant ssh
訪問網站
- 綁定hosts
192.168.10.10 homestead.app
- 訪問
http://homestead.app
登錄
SSH登錄
- 通過ssh登錄
ssh vagrant@127.0.0.1 -p 2222
或者創建別名 alias vm="ssh vagrant@127.0.0.1 -p 2222"
,使用vm登錄
- 通過在Homestead 目錄使用 vagrant ssh 命令
連接虛擬機內Mysql
mysql -h 127.0.0.1:33060 -u homestead -p secret
端口映射
- SSH: 2222 → Forwards To 22
- HTTP: 8000 → Forwards To 80
- HTTPS: 44300 → Forwards To 443
- MySQL: 33060 → Forwards To 3306
- Postgres: 54320 → Forwards To 5432
增加額外端口
ports:
- send: 93000
to: 9300
- send: 7777
to: 777
protocol: udp
增加站點
方式一
- Homestead.yaml 文件中增加站點
- Homestead 目錄中執行 vagrant provision
會破壞以后數據庫
方式二 Homestead環境中的 serve
命令
- SSH 進入 Homestead 環境中
- 執行下列命令
serve domain.app /home/vagrant/Code/path/to/public/directory 80
參考資料