Windows搭建wnmp

來源:互聯網
上載者:User

標籤:批次檔   設定檔   fastcgi   ref   命令   script   運行   location   str   

1. 下載安裝nginx:

nginx官網:http://nginx.org/en/download.html

下載任一版本(我下載的是stable1.12.1版本)解壓到D:\wnmp\nginx(自己決定目錄)目錄下,運行解壓後目錄下的nginx.exe,訪問

http://localhost或http://127.0.0.1,出現以下介面說明nginx已安裝成功:

]

 

若出現403 forbidden,可能是80連接埠被佔用,在命令列執行如下命令查看:netstat -ano | findstr "80" 

若80連接埠確實被其他進程佔用,可以修改nginx設定檔D:\wnmp\nginx\conf\nginx.conf,找到listen 80,把80改成其他沒被使用的連接埠號碼

例如listen 8080,然後重啟nginx訪問http://localhost:8080即可。

 

2. 下載安裝並配置php:

關於php的安裝和配置,可以參考我的另一篇博文——windows7搭建wamp環境,除了這裡安裝路徑為D:\wnmp\php,其它操作都一樣,

這裡不再贅述。

 

3. 配置nginx支援php:

修改nginx設定檔D:\wnmp\nginx\conf\nginx.conf:

(1)

location / {

        root   html;

        index  index.html index.htm;

}

改為:

location / {

        root   D:/wnmp/nginx/html;

        index  index.html index.htm index.php;

}

(2)

#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;

 #}

改為:

location ~ \.php$ {

        root           D:/wnmp/nginx/html;

        fastcgi_pass   127.0.0.1:9000;

        fastcgi_index  index.php;

        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

        include        fastcgi_params;

}

 

4. 測試nginx是否成功支援php:

這裡和apache不同,需要同時開啟php和nginx。

(1)命令列開啟php:

(2)命令列開啟nginx:

(3)建立php檔案並訪問:

建立並編輯一個php檔案放在D:/wnmp/nginx/html目錄下,例如:建立一個phpinfo.php檔案,內容:

<?php phpinfo(); ?>

訪問http://localhost/phpinfo.php(若不是使用80連接埠記得要加上連接埠號碼訪問),出現以下介面說明nginx已成功支援php:

 

 

鑒於這種需要同時開啟php和nginx的方式比較麻煩,而且開啟php的cmd視窗還不能關閉,關閉視窗的話php也會關閉,可以使用一種比較便捷的方法來同時啟動和關閉php與nginx。

註:以下內容引用自https://www.inbeijing.org/archives/1181。

首先需要下載一個RunHiddenConsole檔案,然後建立兩個bat批次檔,內容如下:

start_nginx.bat:

@echo off

REM set PHP_FCGI_CHILDREN=5

set PHP_FCGI_MAX_REQUESTS=1000

echo Starting PHP FastCGI…

RunHiddenConsole D:/wnmp/php/php-cgi.exe -b 127.0.0.1:9000 -c D:/wnmp/php/php.ini

echo Starting nginx…

RunHiddenConsole D:/wnmp/nginx/nginx.exe -p D:/wnmp/nginx

 

stop_nginx.bat:

@echo off

echo Stopping nginx…

taskkill /F /IM nginx.exe > nul

echo Stopping PHP FastCGI…

taskkill /F /IM php-cgi.exe > nul

exit

 

將這兩個檔案儲存在和RunHiddenConsole檔案相同的目錄下,以後點擊start_nginx.bat檔案即可同時開啟php與nginx,點擊stop_nginx.bat則將它們同時關閉。

附上此三個檔案下載連結(同樣來自https://www.inbeijing.org/archives/1181,在此對博主表示感謝!):

http://www.inbeijing.org/wp-content/uploads/2015/06/RunHiddenConsole.zip

 

5. 下載安裝mysql:

同樣參考我的另一篇博文——windows7搭建wamp環境,這裡亦不再重複描述。

 

至此,wnmp開發環境成功搭建完成!

 

 

 

 

 

 

 

 

Windows搭建wnmp

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.