Windows下配置wnmp

1.下载所需的软件,分别是nginx,php,mysql,安装所需的软件

2.在C盘根目录下新建wnmp文件夹,分别建立文件夹mysql,nginx,php.解压相对应的文件到指定目录下

C:\wnmp\mysql

C:\wnmp\nginx

C:\wnmp\php

3.安装nginx

1)打开C:\nginx目录,运行该文件夹下的nginx.exe

2)测试是否启动nginx。打开浏览器访问http://localhosthttp://127.0.0.1,看看是否出现“Welcome to nginx!”,出现的证明已经启动成功了。没有启动的话,看看80端口有占用没。(端口可以在nginx.conf中更改)

注意:该网站的默认目录在“C:\wnmp\nginx\html”下

第三部分:安装php(这里主要讲nginx配置启动php,以cgi运行php)

nginx配置文件是conf文件夹里的nginx.conf

1*.修改大概第43~45行之间的

1
2
3
4
location / {
root C:/wnmp/nginx/html;
index index.html index.htm index.php;
}

2*.支持php的设置

修改大概在第63-71行的

先将前面的“#”去掉,同样将root html;改为root C:/wnmp/nginx-1.5.8/html;。再把“/scripts”改为“$document_root”,这里的“$document_root”就是指前面“root”所指的站点路径,这是改完后的:

1
2
3
4
5
6
7
8
9
pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
root C:/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;
}

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,

1
<?php phpinfo(); ?>

访问http://localhost/phpinfo.php

或者http://127.0.0.1/phpinfo.php

出现如下的信息就说明php已经成功安装:

第三部分试运行以及编辑运行配置文件

C:\wnmp\php>php-cgi.exe -b 127.0.0.1:9000-c C:\wnmp\php\php.ini
重新运行nginx.exe。