1. 程式人生 > >windows7搭建wnmp環境

windows7搭建wnmp環境

process type clas nec htm red cati keepal ...

官方下載地址

  • Nginx
  • MySql
  • PHP

到官網上下載對應版本壓縮包,我下載的是分別是nginx1.12.1,mysql5.6.37,php5.6.31。

【php5.6.31須安裝VC11運行庫即Visual C++ Visual Studio 2012,下載地址:https://www.microsoft.com/zh-CN/download/details.aspx?id=30679】

一:安裝Nginx

把下載下來的nginx-1.12.1.zip文件,解壓到指定的目錄(更名為:nginx1.12.1)就OK了,下面貼一下我的目錄結構哦(我在目錄下多安裝了一個redis)

技術分享

雙擊nginx1.12.1目錄下面nginx.exe文件來啟動服務器,在瀏覽器地址中輸入localhost ,如出現下圖說明安裝成功了!

技術分享

二:安裝MySql

解壓mysql-5.6.37-winx64.zip壓縮包(重命名mysql5.6.37)然後會看到一個my-default.ini文件,在本目錄下復制一個my-default.ini並重命名為my.ini,
修改兩處為:

basedir = E:\wnmp\mysql5.6.37
datadir = E:\wnmp\mysql5.6.37\data

技術分享

win+R鍵打開cmd,進入mysql安裝目錄下bin文件夾中。

輸入mysqld install安裝mysql服務,如下圖所示,(因為我已經安裝了服務,所以會提示已經存在)

技術分享

輸入net start mysql啟動服務(我已經啟動了)

技術分享

(說明:windows7環境下安裝mysql一般會提示錯誤如:“應用程序無法正常啟動0xc000007b”或“MSVCP110.dll丟失”,這時候可以下載"DirectX修復工具"該工具修復)

技術分享

三:安裝php
將壓縮文件解壓到目錄並重命名為php5.6.31,配置php.ini文件,php提供了兩個模板,php.ini-development和php.ini-production,前者適合開發程式使用(測試用),

後者擁有較高的安全性設定,則適合上線當產品使用。這裏我們將php.ini-development文件改為php.ini做配置文件使用。


修改擴展dll文件目錄:

//這裏根據自己的實際情況而定
extension_dir = "E:\2015\wnmp\php\ext"

加入擴展:

選擇需要運行哪些擴展,只需將extension前面的註釋去掉,例如:

extension=php_mysql.dll
extension=php_mysqli.dll

CGI 設置

enable_dl = On
cgi.force_redirect = 0
cgi.fix_pathinfo=1
fastcgi.impersonate = 1
cgi.rfc2616_headers = 1

4:配置

這裏所說的配置,主要是講如何讓Nginx對PHP提供支持!!打開nginx目錄下conf文件夾裏的nginx.conf(這就是我的配置文件了)

技術分享

可直接復制下面的代碼:

worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
gzip on;
server {
listen 80;
server_name localhost;
location / {
root E:/wnmp/www;
index index.html index.htm index.php;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ \.php$ {
root E:/wnmp/www;
fastcgi_pass 127.0.0.1:9001;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}

測試:

啟動php內置的cgi程序,在9000端口監聽nginx發過來的請求:

E:\wnmp\php5.6.31>php-cgi.exe -b 127.0.0.1:9000 -c E:\wnmp\php5.6.31\php.ini

PS:上一步操作中如果沒有重啟nginx的話,現在重啟一遍吧!!

在網站根目錄(www目錄)下創建phpinfo.php文件,在瀏覽器地址欄中輸入http://localhost/phpinfo.php, 顯示如下表示php安裝成功。

技術分享

RunHiddenConsole配置:

首先把下載好的RunHiddenConsole.zip包解壓到nginx目錄內,RunHiddenConsole.exe的作用是在執行完命令行腳本後可以自動關閉腳本,而從腳本中開啟的進程不被關閉。

【百度RunHiddenConsole.exe自行下載】

創建start_nginx.bat文件:

@echo off  
set php_home=../php5.6.31/
set nginx_home=./
echo Starting PHP FastCGI...
RunHiddenConsole %php_home%/php-cgi.exe -b 127.0.0.1:9001 -c %php_home%/php.ini
echo Starting nginx...
RunHiddenConsole %nginx_home%/nginx.exe -p %nginx_home%
exit

創建stop_nginx.bat腳本,對應的是用來關閉nginx服務:

@echo off  
echo Stopping nginx...
taskkill /F /IM nginx.exe > nul
echo Stopping PHP FastCGI...
taskkill /F /IM php-cgi.exe > nul
exit

文件目錄結構如下:

技術分享

至此配置完畢!!!

windows7搭建wnmp環境