1.下载nginx 和php7
a.下载地址
php下载地址:http://php.net/downloads.php
nginx下载地址:http://nginx.org/
windows运行时库,vc_redist.exe下载地址:https://www.microsoft.com/en-us/download/confirmation.aspx?id=21254
b.php下载选择
下载选择,我选的是最新的PHP7,64位的版本,线程安全的,如下图:
c.nginx下载选择
我下载的是1.10.1,稳定的windows的版本,写本文的时候已经到1.10.2了。
d.下载个vc_redist.x64
e.解压缩
2.配置nginx
a. 端口,服务器名,字符集
b.工作目录
<span style="font-family:Microsoft YaHei;">location / {
root html;
index index.html index.htm;
}</span>
将以上部分改为<span style="font-family:Microsoft YaHei;">location / {
root D:/kong66/HTML/www;
index index.php index.html index.htm;
}</span>
root 定义了工作空间,也就是我们php项目所在的目录。
加入index.php是为了让nginx能够识别php脚本,否则,在访问php文件时,会出现直接下载的情况。
c.关联php
将location ~ \.php配置部分的注释全部去掉,最终配置如下:
<span style="font-family:Microsoft YaHei;">location ~ \.php$ {
root D:/kong66/HTML/www;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}</span>
注意这里面的$document_root变量,它对应的内容就是root参数值,如果我们没有定义root参数或者把root注释掉,在访问php的时候,
页面上就会出现No input file specified.提示。
3.php配置
将php.ini-development 重命名为 php.ini,对其中的配置进行修改。
a.更改配置
enable_dl = on
cgi.force_redirect = 0
cgi.fix_pathinfo=1
fastcgi.impersonate = 1
cgi.rfc2616_headers = 1
b.添加扩展
extension_dir = "./ext"
4.启动应用
a.编写一个测试index.php
<span style="font-family:Microsoft YaHei;"><?php
echo "hello world";
echo phpinfo();
?></span>
将以上文件保存在之前设置的工作目录中,D:/kong66/HTML/www
b.启动php
->php-cgi.exe -b 127.0.0.1:9000
c.启动nginx
->start nginx
4.浏览器验证
5.启动优化