首先,材料准备:
php:http://windows.php.net/
nginx: http://nginx.org/en/download.html
mysql: http://www.mysql.com/downloads/
D盘新建wwwroot 文件夹,里面新建php、nginx、www三个文件夹
一、php安装及配置文件修改
从官网下载完需要的版本(以php7为例) ,解压到D:\wwwroot\php\php7 目录中,把php.ini-production 或 php.ini-development 重命名为php.ini,开发测试的话改php.ini-development,正式用的话用php.ini-production,用编辑器打开此文件(最好不要用记事本打开),此文件为PHP配置文件。
查找定位至:; extension_dir = "./" ,将前面的分号去掉并修改为:extension_dir = "D:/wwwroot/PHP7/ext"
查找定位至:;extension=php_gd2.dll,将前面的分号去掉为:extension=php_gd2.dll
查找定位至:;extension=php_mbstring.dll,将前面的分号去掉为:extension=php_mbstring.dll
查找定位至:;extension=php_mysqli.dll,将前面的分号去掉为:extension=php_mysqli.dll
查找定位至:;extension=php_pdo_mysql.dll,将前面的分号去掉为:extension=php_pdo_mysql.dll
查找定位至:;cgi.force_redirect = 1,将前面的分号去掉为:cgi.force_redirect = 1
查找定位至:;cgi.fix_pathinfo=1,将前面的分号去掉为:cgi.fix_pathinfo=1
查找定位至:;cgi.rfc2616_headers = 0,将前面的分号去掉并改为:cgi.rfc2616_headers = 1
二、mysql安装
三、nginx配置php
第45行改为:index index.html index.htm index.php; 加了PHP文件支持。
第65至71行:
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
}
(改为)location ~ \.php$ {
root D:/wwwroot/www;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME D:/wwwroot/www$fastcgi_script_name;
include fastcgi_params;
}
四、启动nginx和php服务
@echo off
echo Starting PHP FastCGI...
RunHiddenConsole d:/wwwroot/PHP7/php-cgi.exe -b 127.0.0.1:9000 -c d:/wwwroot/PHP7/php.ini
echo Starting nginx...
cd /d D:\wwwroot\nginx-1.3.7
nginx.exe
在wwwroot中建立文件stop_nginx.bat
@echo off
echo Stopping nginx...
taskkill /F /IM nginx.exe > nul
echo Stopping PHP FastCGI...
taskkill /F /IM php-cgi.exe > nul
exit
<?php phpinfo(); ?>