標籤:rate postgre virtual 解決 machine 圖形化介面 交流 sse 私密金鑰
一、簡介
1、Homestead
Laravel Homestead是官方預封裝的Vagrant box,提供給我們學習和開發人員一個環境,我們在自己的電腦上不要裝PHP,HHVM,WEB伺服器等其他軟體。也不用擔心環境搭建帶來的問題,Vagrant box全部都會給解決好,我們只需要使用就好。如果有問題,我們可以重新銷毀vagrant box重新安裝一個即可。
2、內建軟體
- Ubuntu 16.04
- Git
- PHP 7.0
- HHVM
- Nginx
- MySQL
- MariaDB
- Sqlite3
- Postgres
- Composer
- Node (附帶了 PM2, Bower, Grunt, and Gulp)
- Redis
- Memcached
- Beanstalkd
2、Vagrant
在這裡會有疑問vagrant是什麼,其實vagrant是一個工具,用於建立和部署虛擬化開發環境的。拿VirtualBox舉例,VirtualBox會開放一個建立虛擬機器的介面,Vagrant會利用這個介面建立虛擬機器,並且通過Vagrant來管理,配置和自動安裝虛擬機器。
二、安裝
1、安裝虛擬機器軟體VirtaulBox或VM(推薦用VirtaulBox),然後安裝vagrant軟體。這裡都是圖形化介面安裝,直接附上軟體的現在地址VirtualBox,Vagrant2、安裝Homestead盒子 在windows控制台中執行如下命令:
vagrant box add laravel/homestead
這個命令會直接從網上下載Homestead盒子大概1G,又是國外的網,所以速度很慢,可以嘗試先用下載工具把Homestead下載下來附上連結:
https://atlas.hashicorp.com/hashicorp/boxes/precise64/versions/1.1.0/providers/virtualbox.box
然後在windows控制台中執行如下的命令,將本地的box與laravel/homestead進行綁定:其中path/to/virtualbox.box是下載後的virtualbox.box的路徑
vagrant box add laravel/homestead /path/to/virtualbox.box
3、安裝Homestead
a. 如果電腦上安裝了Git(沒有的化就先安裝一下),Git有window用戶端直接安裝),直接將homestead項目複製下來,即如下的命令
git clone https://github.com/laravel/homestead.git Homestead
b. 進入Git的Git Bash終端執行如下命令,產生秘鑰和公開金鑰
ssh-keygen -t rsa -C "[email protected]"
c. 從window控制台中進入Homestead檔案夾,執行如下初始化命令
bash init.sh
執行完命令後在C:\User\UserName\.homestead檔案夾下會有Homestead.yaml設定檔,可以在這裡按自己的需求進行配置,內容如下
---
#虛擬機器IP
ip:"192.168.10.10"
#虛擬機器記憶體大小
memory:2048
#虛擬機器cpu數量
cpus:1
#提供虛擬機器類型
provider: virtualbox
#公開金鑰SSH KEY
authorize:~/.ssh/id_rsa.pub
#私密金鑰SSH KEY
keys:
-~/.ssh/id_rsa
#共用資料夾
folders:
- map: D:\Xampp\htdocs\blog #自己電腦上的項目路徑
to:/home/vagrant/Code#映射到虛擬機器中的路徑
#網站配置web伺服器配置
sites:
- map: homestead.app #網域名稱
to:/home/vagrant/Code/blog/public #網域名稱的映射地址
#資料庫配置
databases:
- homestead
# blackfire:
# - id: foo
# token: bar
# client-id: foo
# client-token: bar
# ports:
# - send: 50000
# to: 5000
# - send: 7777
# to: 777
# protocol: udp
d. 啟動測試
①若沒有修改配置項執行如下命令
vagrant up
可以看到終端上顯示,如下結果就說明啟動完成
②若修改了配置項需要執行下面的命令
vagrant up --provision
e. 測試
①SSH測試:現在windows控制台輸入
vagrant ssh
進行SSH串連,執行ls命令查看是否有映射的檔案夾
②瀏覽器訪問虛擬機器網站測試
http://localhost:8000/
在C:\Windows\System32\drivers\etc\hosts添加如下代碼
# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a ‘#‘ symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
# localhost name resolution is handled within DNS itself.
#127.0.0.1 localhost
#::1 localhost
192.168.10.10 homestead.app
在瀏覽器中訪問即可
③、資料連線測試通過本地的串連工具進行串連(在這裡用的是Navicat進行串連),使用者名稱是homestead密碼是secret
三、總結Homestead是個很好用的虛擬環境,只是對於沒有接觸過這些東西的小夥伴們可能會感覺陌生,也會踩很多坑,不過也會越玩越有興趣。感覺Laravel的生態圈越來越完善,Laravel越來越讓人著迷,希望和小夥伴們一起學習交流,後面會更新紀錄自己遇到的坑和一些解決方案。
Laravel學習之Windows下Homestead環境搭建