步骤:
- 1、安装NGINX for win
- 2、安装PHP for win
- 3、安装MYSQL for win
- 4、安装PHPADMIN
下载最新的稳定的nginx的版本 。
nginx的配置和运行
将Nginx配置成WINDOWS服务:
下载WINSW,建立winsw.xml,并输入内容如下:
<service>
02 <id>nginx</id>
03 <name>nginx</name>
04 <description>nginx</description>
05 <executable>c:/nginx/nginx.exe</executable>
06 <logpath>c:/nginx/</logpath>
07 <logmode>roll</logmode>
08 <depend></depend>
09 <startargument>-p c:/nginx</startargument>
10 <stopargument>-p c:/nginx -s stop</stopargument>
11 </service>
运行后将会在WINDOWS服务列表中找到NGINX服务项,将服务设置成自动启动。
修改Nginx配置文件,路径名称C:/nginx/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 1024;
}
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 gbk;
#access_log logs/host.access.log main;
location / {
root E:/www;
index index.html index.htm;
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 html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$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;
# }
#}
}
尝试加载输入测试网页在浏览器中:
http://localhost
如果你看到它,你的安装成功。如需将Nginx配置负载均衡和反向代理,请参考其它资料,本文不作详述。
Nginx的配置PHP
下载PHP最新版本,放置c:/php
一、
首先打开php.ini(修php.ini-development) 找到:
;extension=php_mysql.dll
将前面的 ; 号去掉, 改成:
extension=php_mysql.dll
找到:
extension_dir = “./”
将其改为你的 php 安装目录下 ext 子目录的绝对路径。例如我的:
extension_dir = “D:/php/ext/”
这步很重要 。否则接下来 php 会找不到 php_mysql.dll 模块,无法装载。
指定docroot——php文件的存放目录,即你的documentroot。doc_root = “e:/www”
扩展存放目录 extension_dir——更改为真实的扩展存放地址。extension_dir = “./ext”
默认时区更改——在[Date]里面增加:date.timezone = Asia/ChongQing
因为nginx需要的是cgi方式的php,所以如下几个地方是重点,否则nginx无法打开php文件:
enable_dl = On
cgi.force_redirect = 0
cgi.fix_pathinfo=1
fastcgi.impersonate = 1
cgi.rfc2616_headers = 1
如果你使用MySQL,那么和我一样拷贝php5ts.dll和libmysql.dll(开启MYSQL)至C:/WINDOWS/system32下面。并且拷贝php.ini至C:/WINDOWS目录下。
启动PHP:
php的启动因为要使用cgi方式,所以有些特殊。我参照网上的方法下载了RunHiddenConsole.exe,使用该工具用其执行的cmd窗口会自动关闭,否则你看一个CMD窗口一直在那晃来晃去,头会晕的。
创建start_php.bat,来启动php,文件内容如下:
@echo off
echo Starting PHP FastCGI...
RunHiddenConsole.exe d:/php/php-cgi.exe -b 127.0.0.1:9000 -c d:/php/php.ini
创建stop_nginx.bat,来关闭php和nginx进程,文件内容如下:
@echo off
echo Stopping nginx...
taskkill /F /IM nginx.exe > nul
echo Stopping PHP FastCGI...
taskkill /F /IM php-cgi.exe > nul
exit
安装了mysql后,phpinfo查看没有mysql的话,需要将libmysql.dll拷贝一份至C:/WINDOWS/system32下面即可!
1、修改MySQL下面自带的ini文件。
修改D:/mysql-5