统:windows 7 64位系统
安装之前,首先下载软件:
nginx: http://nginx.org/en/download.html
php stable php 5.6.26: http://php.net/downloads.php
mysql: http://dev.mysql.com/downloads/utilities/
第一步:在d盘建立文件夹nginx+php+mysql,路径为:d:\nginx+php+mysql
第二步:安装nginx,安装目录为:d:\nginx+php+mysql\nginx
1.打开d:\nginx+php+mysql\nginx目录,运行该文件夹下的nginx.exe
2.测试是否启动nginx。打开浏览器访问http://localhost 或 http://127.0.0.1,看看是否出现“welcome to nginx!”,出现的证明已经启动成功了。
若启动不成功,查看是否端口被占用。
安装php,安装目录为:d:\nginx+php+mysql\php
安装mysql,安装目录为: d:\nginx+php+mysql\mysql
第三步:修改nginx的conf文件:目录为d:\nginx+php+mysql\nginx\conf
文件名为:nginx.conf
1. 去掉worker_processes前的#号,开启一个进程
2. 添加events
3. 设置http->设置server->支持php
#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 koi8-r;
#access_log logs/host.access.log main;
location / {
root d:/nginx+php+mysql/nginx/html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# 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 $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}
测试nginx是否安装成功
第四步:修改php下php.ini-development文件,将文件名修改为php.ini,找开php.ini:
搜索“extension_dir”,找到extension_dir = ext 先去前面的分号再改为 extension_dir = ./ext
搜索“php_mysql”,找到:”extension=php_mysql.dll和extension=php_mysqli.dll 去掉前面的“;”extension=php_mysql.dll和extension=php_mysqli.dll (支持mysql数据库)
查看php是否安装成功:
第四步:在php目录下新建文件php-cgi.vbs,用php-cgi.vbs文件启动php-cgi:
打开php-cgi.vbs,写入启动编码:
set wscriptobj = createobject(wscript.shell)
wscriptobj.run php-cgi -b 127.0.0.1:9000,0
第五步:在d:\nginx+php+mysql目录下新建启动项:runserver.bat和停止项stopserver.bat
在启动项runserver.bat中输入:
@echo off
echo starting nginx...
cd %~dp0nginx
start ./nginx.exe
echo starting mysql...
net start mysql
echo starting php fastcgi...
cd %~dp0php
start php-cgi.vbs
pause
exit
在停止项中输入:
@echo off
echo stopping nginx...
taskkill /f /im nginx.exe > nul
echo stopping php fastcgi...
taskkill /f /im php-cgi.exe > nul
echo stopping mysql...
net stop mysql
pause
exit
最后,查看是否启动成功:
在nginx的html目录下d:\nginx+php+mysql\nginx\html,新建phpinfo.php
写入:
在浏览器中输入phpinfo.php的路径,查看是否配置成功: