导言:
1.下载相关安装包
下载nginx :Stable version nginx/Windows-1.2.5
http://nginx.org/en/download.html 也可点此处直接下载http://nginx.org/download/nginx-1.2.5.zip
下载php: VC9 x86 Non Thread Safe (2012-Oct-17 22:45:27)这里我们选择非线程安全版
http://windows.php.net/download/#php-5.4 也可点此处直接下载http://windows.php.net/downloads/releases/php-5.4.8-nts-Win32-VC9-x86.zip
下载RunHiddenConsole
http://redmine.lighttpd.net/attachments/660/RunHiddenConsole.zip
下载MySQL MySQL Installer 5.5.28
http://www.mysql.com/downloads/installer/ 也可点此处直接下载http://cdn.mysql.com/Downloads/MySQLInstaller/mysql-installer-community-5.5.28.3.msi
2.安装
安装nginx
在D盘下建立名为server的目录 D:\server
解压nginx-1.2.5.zip至D:\server\nginx-1.2.5
找到下面的nginx.exe,在命令行下运行nginx.exe (注意目录中不能出现中文字符)
启动nginx
- D:\server\nginx-1.2.5>nginx
打开任务管理器,切换到进程选项卡,出现如下进程,证明nginx已经启动。
在浏览中键入:http://127.0.0.1,看到下图所示证明nginx正常工作。
配置网站根目录
在D:\server下建立www目录
在www目录下新建一个index.html文件,文件内容如下:
- <html>
- <head>
- </head>
- <body>
- test is ok !
- </body>
- </html>
修改D:\server\nginx-1.2.5\conf\nginx.conf
location / {
#root html;
root D:/server/www; #注意路径分隔符为斜杠
index index.html index.htm;
}
重新加载nginx 配置
- D:\server\nginx-1.2.5>nginx -s reload
在浏览中键入:http://127.0.0.1
看到 test is ok !说明工作正常
停止nginx:
- D:\server\nginx-1.2.5>nginx -s stop
显示nginx 帮助
- D:\server\nginx-1.2.5>nginx -h
安装php
- D:\server\php>RunHiddenConsole.exe php-cgi.exe -b 127.0.0.1:9000 -c D:\server\php\php.ini
- D:\server\php>netstat -a
使nginx能将php请求交给php处理
root D:/server/www;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME D:/server/www$fastcgi_script_name;
include fastcgi_params;
}
- <?php
- echo phpinfo();
安装MySQL5.5
(注意:需要安装.net framework 4.0.30319,已经安装有的,跳过此步) 下载地址: http://download.microsoft.com/download/9/5/A/95A9616B-7A37-4AF6-BC36-D6EA96C8DAAE/dotNetFx40_Full_x86_x64.exePHP支持Mysql
- ;extension_dir = "ext"
- ………………
- ;extension=php_mysql.dll
- <?php
- $con = mysql_connect("localhost","root","");
- if (!$con){
- die('Could not connect: ' . mysql_error());
- } else {
- echo 'Database connected successfully';
- }
- mysql_close($con);
一键启动所有服务
在windows下习惯了wamp的朋友,可能会很不习惯这种一个程序一个程序单个启动的方式,这对我们这种懒人来说,不是个好方法。下面我们写两个脚本- @echo off
- echo starting php-cgi...
- D:\server\php\RunHiddenConsole.exe php-cgi.exe -b 127.0.0.1:9000 -c D:\server\php\php.ini
- echo starting nginx...
- cd nginx-1.2.5
- RunHiddenConsole.exe D:\server\nginx-1.2.5\nginx
- echo starting mysql...
- "D:\server\MySQL\MySQL Server 5.5\bin\mysqld"
- exit
- @echo off
- echo stopping nginx...
- taskkill /F /IM nginx.exe > nul
- echo stopping php-cgi...
- taskkill /F /IM php-cgi.exe > nul
- echo stopping mysql...
- taskkill /F /IM mysqld.exe > nul