到 PHP 下載頁下載最新版本的 PHP(若是使用 Laravel 5.1 的話須要 PHP 5.5.9+ 版本),解壓下載的zip格式壓縮文件到本地目錄,好比E:\Php
。php
打開命令行按照以下步驟建立php.ini
文件:html
C:\Users\Test>E: E:\>cd Php E:\Php> copy php.ini-development php.ini
而後在編輯 php.ini
:node
// 將 ; extension_dir = "ext" // 修改成 extension_dir = "ext" // 將 ;extension=php_openssl.dll // 修改成 extension=php_openssl.dll // 將 ;extension=php_mbstring.dll // 修改成 extension=php_mbstring.dll
如今,在 E:\php
目錄下,能夠執行 php
命令:laravel
1)打開Windows控制面板,在頂部右側搜索框搜索」環境變量「:git
2)點擊」編輯帳戶的環境變量「:web
3)雙擊PATH那一行而後將;E:\Php
添加到彈出框的變量值中:npm
下一次打開命令行時,php.exe
已經在用戶變量中,能夠在任何地方直接執行php
命令而不須要指定絕對路徑。json
若是執行php
命令時報錯:gulp
對應解決辦法:http://jingyan.baidu.com/article/4f7d57129fa86e1a201927de.html。ubuntu
咱們將會在本地安裝 Node.js 以便後續使用 gulp。
到 Nodejs 下載頁下載 Windows 系統對應版本安裝。
使用默認設置安裝,安裝完成後打開新的命令行使用以下命令檢查安裝是否成功:
npm install -g gulp
安裝完成後檢查gulp版本:
npm install -g bower
安裝完成後檢查bower版本:
Composer是PHP包依賴管理器。
去 Composer 下載頁下載 Windows 版本安裝程序。使用默認設置安裝,若是問你PHP安裝路徑,輸入:
E:\Php\php.exe
安裝完成後,關掉當前的命令行並打開一個新的,檢查Composer版本驗證是否安裝成功:
安裝過程當中會將E:\Php
從用戶變量移動到系統變量,並添加C:\ProgramData\ComposerSetup\bin
到系統路徑。
在 Windows 中咱們將會安裝本地 Git 軟件並只使用其提供的 Git Bash 設置 SSH Key,任何其它對git的使用都經過命令行實現。
下載git安裝器
到git下載頁下載 Windows 版安裝。
安裝
運行下載的安裝文件並一路選擇默認選項直到這個頁面:
確保選擇「Use Git from the Windows Command Prompt」選項。
餘下部分繼續選擇默認選項進行安裝便可。
檢查Git版本
關閉全部命令行窗口,而後打開一個新的命令行窗口,運行以下命令確保Git安裝成功:
在 Windows 開始菜單找到 Git Bash 並運行,在打開的窗口中執行 ssh-keygen
命令,一路回車使用默認選項來設置SSH Key:
$ ssh-keygen -t rsa -C "your@email.com" Generating public/private rsa key pair. Enter file in which to save the key (/c/Users/LaravelAcademy/.ssh/id_rsa): Created directory '/c/Users/LaravelAcademy/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: $
下面咱們會下載 Laravel Homestead Vagrant 盒子:
C:\Users\LaravelAcademy> vagrant box add laravel/homestead ==> box: Loading metadata for box 'laravel/homestead' box: URL: https://vagrantcloud.com/laravel/homstead
這一步可能須要消耗較長時間,具體取決與你的網絡鏈接速度。
如今讓咱們使用 Composer 安裝 Homestead :
C:\Users\LaravelAcademy> composer global require "laravel/homestead=~2.0" Changed current directory to C:\Users/LaravelAcademy/AppData/Roaming/Composer ./composer.json has been updated Loading composer repositories with package information Updating dependencies (including require-dev) - Installing symfony/process (v2.7.7) Downloading: 100% - Installing symfony/console (v2.7.7) Downloading: 100% - Installing laravel/homestead (v2.1.8) Downloading: 100% symfony/console suggests installing symfony/event-dispatcher () symfony/console suggests installing psr/log (For using the console logger) Writing lock file Generating autoload files
Composer 會將 Homestead 安裝到 Composer 安裝目錄下的 vendor
目錄。
爲了從命令行能夠直接訪問homestead
,將其安裝路徑添加到系統變量便可。和添加PHP路徑到系統變量操做步驟同樣,只是這一次添加的路徑不同而已:
C:\Users\YOU\AppData\Roaming\Composer\vendor\bin;vendor\bin
具體路徑根據你的本地路徑來。
注意:這裏咱們添加
vendor\bin
到系統路徑中,由於每個Laravel項目都會包含這一目錄,將其添加到系統變量後咱們就能夠在項目根目錄下直接使用項目提供的依賴包。
系統變量修改後須要從新打開新的命令行窗口才會生效,因此咱們再一次關閉全部命令行窗口並打開一個新的,而後檢查 Homestead 版本已驗證是否安裝成功:
安裝完 Homestead 並添加 Composer 的 bin
目錄到系統變量後,須要初始化 Homestead :
C:\Users\LaravelAcademy> homestead init Creating Homestead.yaml file... Homestead.yaml file created at: C:\Users\LaravelAcademy\.homestead/Homestead.yaml
記住:一臺機子上只須要初始化一次 Homestead 便可。
在第一次啓動 Homestead 以前咱們要建立一個 Code
目錄用於存放項目文件,而後使用 homestead up
命令啓動虛擬機:
E:> mkdir Code E:> homestead up Bringing machine 'default' up with 'virtualbox' provider... ==> default: Checking if box 'laravel/homestead' is up to date...
若是啓動過程當中出現報錯信息:
There was an error while executing `VBoxManage`, a CLI used by Vagrant for controlling VirtualBox. The command and stderr is shown below. Command: ["hostonlyif", "create"] Stderr: 0%... Progress state: E_FAIL VBoxManage.exe: error: Failed to create the host-only adapter VBoxManage.exe: error: Code E_FAIL (0x80004005) - Unspecified error (extended in fo not available) VBoxManage.exe: error: Context: "int __cdecl handleCreate(struct HandlerArg *,in t,int *)" at line 66 of file VBoxManageHostonly.cpp
解決辦法參考:在 Windows 上進行 Laravel Homestead 安裝、配置及測試
如今 Homestead 虛擬機已經運行起來了,若是你關閉這個 Windows 命令行窗口,虛擬機仍然在後臺運行,除非你在命令行中運行 homestead halt
命令纔會關閉虛擬機。
你能夠登陸到 Homestead 虛擬機,可是在 Windows 系統中不能使用 homestead ssh
,這裏咱們藉助第三方軟件 PuTTY 來登陸到虛擬機。
Windows 系統並無內置 SSH 客戶端軟件,所以咱們須要下載一個並安裝,推薦使用 PuTTY 經過 SSH 登陸到虛擬機。
下載並安裝 PuTTY
下載putty安裝器,運行這個安裝文件,一路使用默認設置便可。
保存 SSH Key
接下來在 Windows 開始菜單中找到 PuTTYgen 並點擊運行,選擇 Conversions 菜單而後點擊 Import Key,進入以前設置 SSH Key 時id_rsa
文件所在目錄並選擇該文件,而後點擊「Save private key」按鈕。若是你想要保存不帶密碼的key,在同一目錄下選擇 id_rsa.ppk
便可。
設置 Homestead PuTTY 會話
啓動 PuTTY 並設置 Connection->SSH->Auth
私有 key 爲剛剛建立的id_rsa.ppk
,設置當前會話的主機名爲vagrant@127.0.0.1
,端口爲2222,保存當前會話名爲 homestead
:
首次運行該會話的時候會彈出一個確認會話框,但以後登陸到 Homestead 虛擬機就再也不須要輸入密碼。
你還能夠在桌面上建立一個該會話的快捷方式,該快捷方式連接指向"C:\Program Files (x86)\PuTTY\Putty.exe" -load homestead
,咱們將其命名爲 Homestead。
修改 PuTTY 的字體
PuTTY 的默認字體是 Courier New
,在我看來很醜,能夠到 PuTTY 的 Windows->Appearance
配置中修改字體、尺寸和顏色等:
經過 PuTTY 鏈接到 Homestead
運行剛剛在 PuTTY 建立的 homestead
會話,登陸到 Homestead 後界面顯示以下:
Using username "vagrant". Authenticating with public key "imported-openssh-key" Welcome to Ubuntu 14.04.2 LTS (GNU/Linux 3.13.0-24-generic x86_64) * Documentation: https://help.ubuntu.com/ Last login: Tue Nov 24 15:46:46 2015 vagrant@homestead:~$
最後一步咱們將會 Windows 上安裝 Laravel 安裝器。
仍是使用 Composer 安裝:
C:\Users\LaravelAcademy> composer global require "laravel/installer=~1.1" Changed current directory to C:\Users/LaravelAcademy/AppData/Roaming/Composer ./composer.json has been updated Loading composer repositories with package information Updating dependencies (including require-dev) - Installing guzzlehttp/promises (1.0.3) Downloading: 100% - Installing psr/http-message (1.0) Downloading: 100% - Installing guzzlehttp/psr7 (1.2.1) Downloading: 100% - Installing guzzlehttp/guzzle (6.1.1) Downloading: 100% - Installing laravel/installer (v1.2.2) Downloading: 100% Writing lock file Generating autoload files
因爲咱們在以前已經設置過了系統變量,這裏 laravel
命令能夠直接從命令行中運行,咱們能夠查看其版本:
好了,至此咱們已經邁出了萬里長征第一步 —— 成功在 Windows 上安裝並設置好了本地開發環境,這將爲咱們後續使用 Laravel 5.1 開發博客應用打下堅實基礎。