nginx : nginx-rtmp-win32 或 nginx/Windows-1.0.4 (無rtmp模塊)php
php:php-5.2.16-nts-Win32-VC6-x86.zip (nginx下php是以FastCGI的方式運行,因此咱們下載非線程安全也就是nts的php包)html
RunHiddenConsole: RunHiddenConsole.zip(用於cmd 非阻塞運行進程)mysql
1)php的安裝與配置。nginx
直接解壓下載好的php包,到D盤wnmp目錄(D:wnmp),這裏把解壓出來的文件夾重命名成php5。進入文件夾修改php.ini-recommended文件爲php.ini,並用Editplus或者Notepad++打開來。找到git
擴展目錄(去掉註釋)github
;extension_dir = "ext"
mysql 擴展(去掉註釋)sql
;extension=php_mysql.dll ;extension=php_mysqli.dll
前面指定了php的ext路徑後,只要把須要的擴展包前面所對應的「;」去掉,就能夠了。這裏打開php_mysql.dll和php_mysqli.dll,讓php支持mysql。固然不要忘掉很重要的一步就是,把php5目錄下的libmysql.dll文件複製到C:Windows目錄下,也能夠在系統變量裏面指定路徑,固然這裏我選擇了更爲方便的方法^_^。shell
到這裏,php已經能夠支持mysql了。windows
接下來咱們來配置php,讓php可以與nginx結合。找到(去掉註釋)安全
;cgi.fix_pathinfo=1
這一步很是重要,這裏是php的CGI的設置。
2)nginx的安裝與配置。
把下載好的nginx-1.0.4的包一樣解壓到D盤的wnmp目錄下,並重命名爲nginx。接下來,咱們來配置nginx,讓它可以和php協同工做。進入nginx的conf目錄,打開nginx的配置文件nginx.conf,找到
worker_processes 1; error_log logs/error.log debug; events { worker_connections 1024; } rtmp { server { listen 1936; application live { live on; pull rtmp://live.hkstv.hk.lxdns.com/live/hks live=1 name=1; } } } http { access_log logs/access.http.log; server_tokens off; default_type application/octet-stream; client_max_body_size 10G; sendfile on; include other.conf; }
當前目錄建立 other.conf
server { listen 7777; server_name live_stream; root www; index index.php; location / { if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=/$1 last; # rewrite mode #rewrite ^(.*)$ /index.php/$1 last; # pathinfo mode } } location ~ \.php$ { fastcgi_hide_header X-Powered-By; fastcgi_pass 127.0.0.1:9000; fastcgi_split_path_info ^(.+\.php)(.*)$; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; } }
保存配置文件,就能夠了。
nginx+php的環境就初步配置好了,來跑跑看。咱們能夠輸入命令
X:\wnp\php\php-cgi.exe -b 127.0.0.1:900 -c X:\wnp\php\php.ini
雙擊nginx.exe
完成!!!
1.start.cmd
@echo off REM Windows 下無效 REM set PHP_FCGI_CHILDREN=5 REM 每一個進程處理的最大請求數,或設置爲 Windows 環境變量 set PHP_FCGI_MAX_REQUESTS=1000 echo Starting PHP FastCGI... RunHiddenConsole D:/wnmp/php5/php-cgi.exe -b 127.0.0.1:9000 -c D:/wnmp/php5/php.ini echo Starting nginx... RunHiddenConsole D:/wnmp/nginx/nginx.exe -p D:/wnmp/nginx
2.end.cmd
@echo off echo Stopping nginx... taskkill /F /IM nginx.exe > nul echo Stopping PHP FastCGI... taskkill /F /IM php-cgi.exe > nul exit
php 文件沒法接收參數,$_GET,$_POST,$_REQUEST,爲空
解決辦法:other.conf 文件中, 「include fast_params」 nginx官網示例
location ~ \.php$ { fastcgi_hide_header X-Powered-By; fastcgi_pass 127.0.0.1:9000; fastcgi_split_path_info ^(.+\.php)(.*)$; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; }