1、准备工作
先到这儿下载官方的nginx for Windows 版本,并到PHP 官方下载php;到mysql官网下载mysql;到memcache官网下载memcache;
2、nginx的安装很简单:解压后双击nginx.exe后服务即启动。这时打开浏览器在地址栏里输入 localhost或者127.0.0.1
如果显示 Welcome to nginx! 表示nginx服务已启动。
3、php安装同样简单,解压后 将php.ini-recommend 改名为php.ini并备份。
4、关键步骤就是nginx启动php的配置和虚拟目录的配置。
服务启动命令:serverstart.cmd php的目录为D:\php5.2.13\
@echo off
REM “正在启动Nginx 服务器……..”
start nginx
REM “开始启动PHP FastCGI………”
set PHP_FCGI_MAX_REQUESTS=1000
echo Starting PHP FastCGI…
RunHiddenConsole.exe D:\php5.2.13\php-cgi.exe -b 127.0.0.1:9000 -c D:\php5.2.13\php.ini
服务停止命令:serverstop.cmd
@echo off
echo Stopping nginx…
taskkill /F /IM nginx.exe > nul
echo Stopping PHP FastCGI…
taskkill /F /IM php-cgi.exe > nul
exit
服务重启命令:serverrestart.cmd
@echo off
echo Stopping nginx.exe…
taskkill /F /IM nginx.exe > nul
echo Stopping PHP FastCGI…
taskkill /F /IM php-cgi.exe > nul
echo Start nginx…
start nginx
echo Starting php-cgi…
RunHiddenConsole.exe D:\PHP5.2.13\php-cgi.exe -b 127.0.0.1:9000 -c D:\PHP5.2.13\php.ini
其中的RunHiddenConsole.exe是隐藏命令终端用的,因为命令当服务启动后命令终端是不会隐藏的,看着很是不舒服,故将其隐藏,下载RunHiddenConsole.exe
下面是nginx.conf的配置:
#user nobody;
#worker_processes 1;
worker_processes 1;
error_log logs/error1.log;
pid logs/nginx.pid;
events {
worker_connections 1024;#每个进程处理的最大连接数65535
}
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 60;
#gzip on;
server
{
listen 80;
server_name localhost;
#Dir Browser
autoindex on;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root D:/Nginx0.8.41/html;
index index.html index.htm index.php;
}
#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:/Nginx0.8.41/html;
}
location ~ \.php$ {
root D:/Nginx0.8.41/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME D:/Nginx0.8.41/html$fastcgi_script_name;
include fastcgi_params;
}
}
include vhost.conf;
}
虚拟目录vhost.conf的配置
server
{
listen 80;
#server_name localtest.soujob.cn soujob.cn *.soujob.cn; #Multi domain renziming Add
#error_page 404 /index.php?module=Error&action=NotFound;
location / {
root D:/PHPproject/localtest.soujob.cn/SouJob;
index index.html index.htm index.php;
}
#rewrite ^/job?(.*)$ /index.php?$1 last;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME D:/PHPproject/localtest.soujob.cn/SouJob$fastcgi_script_name;
include fastcgi_params;
}
}
php.ini的配置:主要就是将extension_dir = “D:\PHP5.2.13\ext” php的扩展目录 ,然后打开php的常用扩展。
然后再nginx的html文件夹中 写phpinfo.php。打开浏览器在地址栏里输入localhost/phpinfo.php 查看结果。
memcache的安装与配置
解压到d:\memcache 。
打开cmd 进入到memcache的目录,输入 memcache.exe -d install 安装
然后再 输入memcache.exe -d start 启动。 即可。
下载php_memcache.dll放在 php的ext扩展目录里,在php.ini中打开即可。