###第一部分:準備工做。(系統:Windows 8.1) ####1.首先是下載軟件。 NGINX-1.3.8官網下載:http://nginx.org/en/download.html PHP5.4.8版本下載地址:http://windows.php.net/download/ Mysql5.5.28版本下載地址:http://www.mysql.com/downloads/mysql/ ####2.安裝mysql軟件。php
####3.解壓NGINX和PHP到你本身安裝位置。 這裏我在C盤新建一個文件夾:wnmp(windows,ngnix,myspq,php),把下面的軟件安裝到這個文件夾裏面。 NGINX目錄C:\wnmp\nginx PHP目錄C:\wnmp\phphtml
###第二部分:安裝nginx ####1.打開C:\nginx目錄,運行該文件夾下的nginx.exe ####2.測試是否啓動nginx。 打開瀏覽器訪問 http://localhost 或 http://127.0.0.1 ,看看是否出現「Welcome to nginx!」,出現的證實已經啓動成功了。沒有啓動的話,看看80端口有佔用沒。 注意:該網站的默認目錄在「C:\wnmp\nginx\html」下mysql
###第三部分:安裝php(這裏主要講nginx配置啓動php,以cgi運行php) nginx配置文件是conf文件夾裏的nginx.conf ####1.修改大概第43~45行之間的nginx
location /{ root html; index index.html index.htm;}
修改網站文件的路徑,以及添加index.php的默認頁。sql
location / { root D:/wnmp/nginx-1.5.8/html; index index.html index.htm inde.php; }
####2.支持php的設置數據庫
修改大概在第63-71行的windows
# 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 /scripts$fastcgi_script_name; # include fastcgi_params; #}
先將前面的「#」去掉,一樣將root html;改成root C:/wnmp/nginx-1.5.8/html;。再把「/scripts」改成「$document_root」,這裏的 「$document_root」就是指前面「root」所指的站點路徑,這是改完後的:瀏覽器
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root C:/wnmp/nginx-1.5.8/html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; # include fastcgi_params; #}
####3.C:\wnmp\php\ext下修改php.ini-development文件 將文件名修改成php.ini,打開php配置文件php.ini,保存便可。 搜索「extension_dir」,找到: e;xtension_dir = "ext" 先去前面的分號再改成 extension_dir = "C:\wnmp\php\ext" 搜索「date.timezone」,找到:;date.timezone = 先去前面的分號再改成 date.timezone = Asia/Shanghai 搜索「enable_dl」,找到:enable_dl = Off 改成 enable_dl = On 搜索「cgi.force_redirect」 ;cgi.force_redirect = 1 先去前面的分號再改成 cgi.force_redirect = 0 搜索「fastcgi.impersonate」,找到: ;fastcgi.impersonate = 1 去掉前面的分號 搜索「cgi.rfc2616_headers」,找到:;cgi.rfc2616_headers = 0 先去前面的分號再改成 cgi.rfc2616_headers = 1測試
搜索「php_mysql」,找到:」extension=php_mysql.dll和extension=php_mysqli.dll 去掉前面的「;」extension=php_mysql.dll和extension=php_mysqli.dll (支持MYSQL數據庫)網站
其餘的配置請按照本身的需求更改。
###試運行以及編輯運行配置文件
C:\wnmp\php-5.5.7-nts-Win32-VC11-x86>php-cgi.exe -b 127.0.0.1:9000-c C:\wnmp\php-5.5.7-nts-Win32-VC11-x86\php.ini
從新運行nginx.exe。
C:\wnmp\nginx-1.5.8\html下新建一個phpinfo.php, <?php phpinfo(); ?>
訪問http://localhost/phpinfo.php 或者http://127.0.0.1/phpinfo.php 出現以下的信息就說明php已經成功安裝:
下載一個RunHiddenConsole.exe,百度網盤。 開啓php-cgi和nginx.exe,保存爲start.bat
[@echo](http://my.oschina.net/echolee1987) off echo Starting PHP FastCGI... C:\wnmp\nginx\RunHiddenConsole.exe C:\wnmp\PHP\php-cgi.exe -b 127.0.0.1:9000-c D:\PHP\php.ini echo Starting nginx... C:\wnmp\nginx\RunHiddenConsole.exe D:/nginx/nginx.exe -p D:/nginx
中止php-cgi和nginx.exe,保存爲stop.bat
[@echo](http://my.oschina.net/echolee1987) off echo Stopping nginx... taskkill /F /IM nginx.exe > nul echo Stopping PHP FastCGI... taskkill /F /IM php-cgi.exe > nul exit