Homestead離線安裝

不知道啥緣由本機的Homestead環境各類報錯沒法使用,因而就從新安裝。在使用vagrant box add laravel/Homestead命令安裝,也遇到各類奇葩情況,結果折騰了一天,最後各類谷歌,才用離線的方法安裝成功php

1.安裝virtualbox、vagrant和git。通常選擇最新版本的軟件便可.

注意:mysql

1.virtualbox版本5.0.28有問題,我用的老版本5.0.10。nginx

2.請將virtualbox進行以下圖所示進行操做,若是不進行此操做,會卡在default: SSH auth method: private key這裏。laravel

==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: bridged
==> default: Forwarding ports...
    default: 22 => 2222 (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key

圖片描述

2.添加homestead鏡像

1.若是直接運行官方命令vagrant box add laravel/Homestead,會因爲網速緣由出現各類問題,若是網絡好請直接運行該命令。git

2.若是網絡情況很差,能夠在http://pan.baidu.com/s/1hrN55w4下載。github

2.1 創建metadata.json文件,將該文件放在和下載BOX同目錄sql

{
    "name": "laravel/homestead",
    "versions": [{
        "version": "0.6.0",//BOX版本號
        "providers": [{
            "name": "virtualbox",
            "url": "file:///Users/Dev/Box/Homestead/homestead-virtualbox-0.6.0.box" //BOX路徑
        }]
    }]
}

2.2 終端進入virtualbox.box所在目錄,使用vagrant box add metadata.json進行安裝apache

3.克隆和修改homestead配置文件。在git bash根目錄下git clone https://github.com/laravel/homestead.git Homestead

1.生成Homestead.yaml文件。切換至Homestead目錄cd Homestead,運行命令sh init.sh生成Homestead.yaml文件,文件位於根目錄.homestead下,文件內容以下:json

---
ip: "2.2.2.2"
memory: 2048
cpus: 1
provider: virtualbox

authorize: ~/.ssh/id_rsa.pub

keys:
    - ~/.ssh/id_rsa

folders:
    - map: /Documents/Dev/Homestead/Code/  //本機目錄
      to: /home/vagrant/Code/              //虛擬機映射目錄
      type: "nfs"                          //最好加這個,我以前沒加,打開運行頁面很慢

sites:
    - map: homestead.app
      to: /home/vagrant/Code/

databases:
    - homestead

# blackfire:
#     - id: foo
#       token: bar
#       client-id: foo
#       client-token: bar

# ports:
#     - send: 50000
#       to: 5000
#     - send: 7777
#       to: 777
#       protocol: udp

2.修改homestead.rb文件,將config.vm.box_version = settings["version"] ||= ">= 0.4.4"修改成config.vm.box_version = settings["version"] ||= ">= 0"bash

注意:

請注意PHP的版本,因爲最新的homestead配置文件PHP版本爲7.1,可能咱們下載BOX的版本爲7.0,因此須要將script目錄中全部文件的php7.1-fpm修改成php7.0-fpm。若是PHP版本爲7.1,則無需修改。

├── blackfire.sh
├── clear-nginx.sh
├── clear-variables.sh
├── create-mysql.sh
├── create-postgres.sh
├── cron-schedule.sh
├── homestead.rb
├── install-maria.sh
├── serve-apache.sh
├── serve-hhvm.sh
├── serve-laravel.sh
├── serve-proxy.sh
└── serve-symfony2.sh

3.修改host文件

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1    localhost
255.255.255.255    broadcasthost
::1             localhost 
2.2.2.2 homestead.app

4.使用命令vagrant up --provision啓動

5.訪問網站,使用網址http://homestead.app訪問便可

相關文章
相關標籤/搜索