因為工作上的成本需求= ="
需要把nginx + php 7安裝到windows server之內.
(放著好好linux server不選,硬要選一個不匹配的
這次就記錄一下把nginx + php 7裝進windows server 2012 r2
預先準備
Nginx 1.9.14下載 http://nginx.org/download/nginx-1.9.14.zip
Php 7.0.6下載 http://windows.php.net/downloads/releases/php-7.0.6-Win32-VC14-x64.zip
http://windows.php.net/downloads/releases/archives/php-7.0.6-Win32-VC14-x64.zip
Visual C++ Redistributable for Visual Studio 2015 下載 https://download.microsoft.com/download/9/3/F/93FCF1E7-E6A4-478B-96E7-D4B285925B00/vc_redist.x64.exe
Visual C++ Redistributable for Visual Studio 2015
Double click=> 結束
Php 7,很簡單
下載時會發現有以下差異,
Non Thread Safe vs Thread Safe ? => php網站放在IIS上執行,就選NTS;在nginx 或 apache上,選TS.
VC 9 vs VC 11 vs VC 14 ? => 編譯的Vusual Studio版本 2008, 2012, 2015.
載下來 -> 解壓(假設解壓到c:\php) -> 配置
複製php.ini-development,改為php.ini
設定php module
打開php.ini
將;cgi.fix_pathinfo=1分號拿掉,不拿也可,預設值是1
;extension_dir = "ext"
;extension=php_curl.dll
;extension=php_gd2.dll
;extension=php_mbstring.dll
;extension=php_openssl.dll # 這是因為我要用到SSL,非必要
將以上模組啟用(就是把註解;拿掉)
啟用fast-cgi,重要
因為在windows下,nginx要執行php其實是透過cgi在溝通,在cmd下執行
c:/php/php-cgi.exe -b 127.0.0.1:9000 -c c:/php/php.ini
Nginx,一樣很簡單
載下來->解壓縮(假設c:\nginx)->配置
配置檔位置
./conf/nginx.conf
將原本的註解拿掉,如下所示(針對的是server{...}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
可以在裡面加入include c:/nginx/conf/conf.d/*.conf; #如果你稍後使用RunHiddenConsole,並且不是在c:\nginx 下執行bat file, 則此處一定要絕對路徑
將server{...}分成一個個配置檔,
linux下也是這樣操作的,比較習慣.
在cmd目錄c:\nginx下執行
start nginx or nginx.exe
重載配置檔
nginx -s reload
停止服務
nginx -s quit or nginx -s stop
當php-cgi與nginx都開啟後,可以檢查工作管理員
但這樣開兩個cmd似乎很蠢,
這時下載公用小程式 RunHiddenConsole 寫兩個batch files來快速啟用 停用nginx + php
啟用服務 nginx_server_start.bat
@echo off
set php_home_dir=C:/php
set nginx_home_dir=C:/nginx
set PHP_FCGI_MAX_REQUESTS=1000
echo Starting PHP FastCGI...
RunHiddenConsole %php_home_dir%/php-cgi.exe -b 127.0.0.1:9000 -c %php_home_dir%/php.ini
echo Starting nginx...
RunHiddenConsole %nginx_home_dir%/nginx.exe -p %nginx_home_dir%
停止服務 nginx_server_stop.bat
@echo off
echo Stopping nginx...
taskkill /F /IM nginx.exe > nul
echo Stopping PHP FastCGI...
taskkill /F /IM php-cgi.exe > nul
exit
最後加到windows 開機執行就可以了
參考