windows下配置wnmp

最近尝试windows下配置nginx+php+mysql,在这里总结一下。

1、下载windows版本的nginx,官网​下载地址:http://nginx.org/en/download.htm,下载好后解压到D:\wnmp

​2、配置php

​下载windows版本的php,官网下载地址:http://windows.php.net/download/,php将会以cgi的方式运行,解压下载好的php包,到D盘wnmp目录(D:\wnmp),这里把解压出来的文件夹重命名成php5。

进入文件夹修改php.ini-development文件为php.ini​。

打开php.ini,找到以下代码

extension_dir ="./ext"更改为extension_dir ="D:/wnmp/php5/ext"
;extension=php_mysql.dll 去掉分号
;extension=php_mysqli.dll 去掉分号(打开数据库动态链接库)

然后把php5目录下的libmysql.dll文件复制到C:\Windows目录下,或者设置环境变量路径也可以,然后找到以下代码

;cgi.fix_pathinfo=0 去掉分号并改为 cgi.fix_pathinfo=1

3、配置nginx

解压后打开conf目录下的nginx.conf文件,找到

        location / {
            root   html;
            index  index.html index.htm;
        }
        #error_page  404              /404.html;
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}
        # 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;
        #}

改为:

        location / {
            root   d:/www;  //自行设置目录
            index  index.html index.htm;
        }
        error_page  404              /404.html;
         redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   d:/www;
        }
         proxy the PHP scripts to Apache listening on 127.0.0.1:80
        
        location ~ \.php$ {
            proxy_pass   http://127.0.0.1;
        }
         pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        
        location ~ \.php$ {
            root           d:/www;
            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

输入命令:

D:\wnmp\php5>php-cgi.exe -b 127.0.0.1:9000 -c D:/wnmp/php5/php.ini

以cgi的方式运行php,监听nginx从9000端口发来的数据。双击nginx.exe运行nginx。 

快捷启动设置:先下载RunHiddenConsole.exe这个文件放入nginx目录中,然后将以下代码保存为start_nginx.bat

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

将以下代码保存为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

最后文件是这样的,双击start_nginx.bat就可以启动nginx和php了。

 

 

5、安装配置mysql
下载mysql:http://dev.mysql.com/downloads/mysql/,然后解压到D:/mnmp目录下
在my-default.ini中找到
basedir=D:\wnmp\MySQL\ 去掉#(mysql所在目录)
datadir
=D:\wnmp\MySQL\data 去掉#(mysql所在目录\data)

命令行进入目录:cd D:\wnmp\MySQL\bin,输入以下命令安装mysql:mysqld -install  (安装后可以在服务中找到)

启动服务:net start mysql,关闭服务:net stop mysql 。也可以在服务中启动或者关闭。

添加path变量:在计算机>属性>高级系统中设置>环境变量中添加:D:\phpenv\mysql\bin
登录命令:mysql -h 主机ip -u 用户名 -p 用户密码
 
 
posted @ 2016-05-16 16:54  plux  阅读(2563)  评论(4编辑  收藏  举报