主要步驟
-
安裝vagrant、VirtualBox、git 工具
-
vagrant box add laravel/homestead
-
克隆homestead 倉庫下來
-
配置Homestead.yaml
-
初始化vagrant配置,啟動vagrant 並登錄虛擬機
參考相關文章:
第一步:下載vagrant、VirtualBox、git 工具步驟省略,比較簡單
第二步:
直接命令行 vagrant box add laravel/homestead 的話,下載會很慢
中間試過直接用迅雷下載,但是還是有點麻煩,要自己在創建metadata.json文件

下載好 lc-homestead-8.2.1-2019112300 box壓縮包,解壓,然后進入目錄執行命令 vagrant box add metadata.json 添加
需要注意的是:
將metadata.json文件中的 name字段修改為laravel/homestead,在后面vagrant up的時候會去檢查box 'laravel/homestead'是否存在的,如果找不到,就會又遠程下載

/f/lc-homestead-8.2.1-2019112300 $ vagrant box add metadata.json ==> box: Loading metadata for box 'metadata.json' box: URL: file://F:/lc-homestead-8.2.1-2019112300/metadata.json ==> box: Adding box 'laravel/homestead' (v8.2.1) for provider: virtualbox box: Downloading: virtualbox.box box: ==> box: Successfully added box 'laravel/homestead' (v8.2.1) for 'virtualbox'!
查看是否導入box成功
$ vagrant box list laravel/homestead (virtualbox, 8.2.1)
第三步: 克隆homestead 倉庫下來
$cd ~ $ git clone https://git.coding.net/summerblue/homestead.git Homestead
進入 ~/homestead 文件夾
vagrant up
錯誤
$ vagrant up Bringing machine 'homestead-7' up with 'virtualbox' provider... ==> homestead-7: Importing base box 'laravel/homestead'... ==> homestead-7: Matching MAC address for NAT networking... ==> homestead-7: Checking if box 'laravel/homestead' version '8.2.1' is up to date... ==> homestead-7: Setting the name of the VM: homestead-7 Vagrant is currently configured to create VirtualBox synced folders with the `SharedFoldersEnableSymlinksCreate` option enabled. If the Vagrant guest is not trusted, you may want to disable this option. For more information on this option, please refer to the VirtualBox manual: https://www.virtualbox.org/manual/ch04.html#sharedfolders This option can be disabled globally with an environment variable: VAGRANT_DISABLE_VBOXSYMLINKCREATE=1 or on a per folder basis within the Vagrantfile: config.vm.synced_folder '/host/path', '/guest/path', SharedFoldersEnableSymlinksCreate: false ==> 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) => 8000 (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... There was an error while executing `VBoxManage`, a CLI used by Vagrant for controlling VirtualBox. The command and stderr is shown below. Command: ["startvm", "259ca5bb-1f5d-401b-bf59-c1fba7b44e1b", "--type", "headless"] Stderr: VBoxManage.exe: error: Not in a hypervisor partition (HVP=0) (VERR_NEM_NOT_AVAILABLE). VBoxManage.exe: error: VT-x is disabled in the BIOS for all CPU modes (VERR_VMX_MSR_ALL_VMX_DISABLED) VBoxManage.exe: error: Details: code E_FAIL (0x80004005), component ConsoleWrap, interface IConsole
解決方法:
開啟電腦Hyper-V功能,需兩步操作
-
重啟電腦,進入bios打開 開啟intel VT選項
開啟兩個選項:
-
“Intel Virtualization Techonlogy”設置 【Enabled】
-
“VT-d”(搭載Intel CPU機台)開啟
-
window 打開 “程序與功能”啟用或關閉Window功能 打開Hyper-v功能

第四步:配置Homestead.yaml
folders: - map: ~/code to: /home/vagrant/code sites: - map: laraveltest.test to: /home/vagrant/code/laraveltest/public
然后系統host文件添加ip地址對應的域名
subl C:/Windows/System32/Drivers/etc/hosts
添加
192.168.10.10 laraveltest.test
第五:啟動虛擬機並進入
進入~/homestead文件夾,啟動 vagrant
vagrant up
成功啟動,登錄 Homestead 虛擬機上
$ vagrant ssh Welcome to Ubuntu 18.04.3 LTS (GNU/Linux 4.15.0-64-generic x86_64) Thanks for using _ _ _ | | | | | | | |__ ___ _ __ ___ ___ ___| |_ ___ __ _ __| | | '_ \ / _ \| '_ ` _ \ / _ \/ __| __/ _ \/ _` |/ _` | | | | | (_) | | | | | | __/\__ \ || __/ (_| | (_| | |_| |_|\___/|_| |_| |_|\___||___/\__\___|\__,_|\__,_| * Homestead v10.0.0 released * Settler v9.1.0 released 257 packages can be updated. 103 updates are security updates. Last login: Sat Nov 23 10:55:29 2019 from 10.0.2.2
homestead mysql 賬號密碼
用戶名:homestead
密碼:secret
命令行登陸:$ mysql -uhomestead -psecret