现在的位置: 首页电子电脑>正文
WNMP nginx+php5+mysql测试环境安装(Windows7)
2010年05月29日 电子电脑 暂无评论

(更新中.. 软件安装在D:webserver下,网站根目录D:webroots)

1. 安装php

下载:http://windows.php.net/download/

这里下载PHP 5.2 (5.2.13)版本的VC6 x86 Non Thread Safe (2010-Feb-24 15:38:53) ZIP [9.95MB]

(最新的版本5.3.2一些软件不支持,比如下面的Zend Optimizer)

Notes:php版本选择

a.VC6版本是使用Visual Studio 6编译器编译的,如果你的php是用Apache来架设,就选择vc6版本;VC9版本是使用Visual Studio 2008编译器编译的,如果你的php使用IIS来架设的,就选择vc9版本

b.PHP的两种执行方式:ISAPI和FastCGI。ISAPI执行方式是以DLL动态库的形式使用,可以在被用户请求后执行,在处理完一个用户请求后不会马上消失,所以需要进行线程安全检查,这样来提高程序的执行效率,所以如果是以ISAPI来执行PHP,建议选择Thread Safe版本;而FastCGI执行方式是以单一线程来执行操作,所以不需要进行线程的安全检查,除去线程安全检查的防护反而可以提高执行效率,所以,如果是以FastCGI来执行PHP,建议选择Non Thread Safe版本。

解压缩至D:webserverphp-5.2.13

复制一份php.ini-recommended,更名为php.ini。查找下面几项,更改php.ini配置:其中extension_dir指定扩展位置;

error_reporting = E_ALL display_errors = On extension_dir = "D:webserverphp-5.2.13ext" doc_root = cgi.fix_pathinfo = 1

 

doc_root默认为空,不要指定,否则提示"No input file specified"

最后一句解除注释,允许修正地址,nginx将php请求交与Fast CGI Server处理

 (尚未开启mysql和pdo)

2. 安装nginx

下载:http://nginx.org/en/download.html

这里也下载了最新的nginx/Windows-0.8.36

解压缩至D:webservernginx-0.8.36

将confnginx.conf配置如下:

#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 64; } http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server { listen 80; server_name localhost; charset utf-8; #access_log logs/host.access.log main; location / { root D:webroot; index index.html index.php; autoindex on; } #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 D:/webroot; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME D:/webroot$fastcgi_script_name; include fastcgi_params; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /.ht { # deny all; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443; # server_name localhost; # ssl on; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_timeout 5m; # ssl_protocols SSLv2 SSLv3 TLSv1; # ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} }

 其中

worker_processes 1;只默认开启一个进程

work_connections 64;测试服务器的话,一个进程允许64个最大连接数就可以了

server中listen 80;常与IIS冲突,在logserror.log中会看到如下提示:

2010/05/03 23:22:02 [emerg] 3492#5004: bind() to 0.0.0.0:80 failed (10013: An attempt was made to access a socket in a way forbidden by its access permissions)

解决办法最好关闭IIS或更改掉IIS开启的端口

location / 指定网站根目录

添加autoindex on;允许目录结构查看

在location ~ .php$中修改nginx,将php请求转发给PHP FastCGI Server.

这里SCRIPT_FILENAME路径最好使用/,防止用被解析为特殊字符,如t是制表符

3. 开启关闭nginx

开启:

在php-5.3.2目录下新建bat如下,开始php-cgi,开启后任务管理器能看到php-cgi.exe

php-cgi -b 127.0.0.1:9000

php-cig这个dos窗口需要长开着,如果需要隐藏可以去这里下载一个小软件

http://blogbuildingu.com/files/RunHiddenConsole.zip

然后双击nginx.exe,任务管理器能看到nginx.exe

在D:webroot目录下新建index.php

<?php phpinfo(); ?>

访问http://localhost/就可以正常使用了

关闭:

新建bat如下

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

Wopus问答

给我留言

留言无头像?


×
腾讯微博