本文参考了 http://www.cnblogs.com/huayangmeng/archive/2011/06/15/2081337.html
近几年来nginx的市场占有率逐渐上升,已经慢慢的逼近了apache,而IIS则首次跌破到10%以下。国内很多大厂的服务器都换成了nginx,依我看它未来应该会超过apache的。
Nginx是俄罗斯人Igor Sysoev编写的轻量级HTTP服务器,它是高性能和反向代理服务器,同时也是一个IMAP/POP3/SMTP 代理服务器。
特点:
处理静态文件,索引文件以及自动索引;打开文件描述符缓冲.
无缓存的反向代理加速,简单的负载均衡和容错.
FastCGI,简单的负载均衡和容错.
1.首先需要的应用程序包。
PHP: VC14 x64 Non Thread Safe (2017-Apr-12 02:22:49) (nginx下php是以FastCGI的方式运行,所以我们下载非线程安全也就是nts的php包)
Nginx: nginx/Windows-1.12.1 (下载stable version)
RunHiddenconsole: RunHiddenconsole.zip (后面会用到)
2.安装与配置。
1)php安装与配置。
将下载好的php包文件解压到某一个目录下,例如我的是:C:\wnmp。把解压后的文件目录改为php7,将里面的php.ini-recommended文件复制一份并改名为php.ini,用文本编辑器将它打开。
将里面的
改为
将下面两个扩展前面的“;”去掉。(因为php7不支持MySQL扩展了,所以这里只有mysqli和pdo扩展)
最后让PHP支持nginx,将下面一行前面的“;”去掉。
2)nginx安装与配置。
先在C:/wnmp目录下新建一个www文件夹,作为服务器的根目录。
将下载好的nginx包文件解压到C:\wnmp目录下,重命名为nginx。打开nginx\conf下的nginx.conf文件来配置nginx。
将
改为
再将
改为
保存好配置即可。
3.启动。
手动启动php和nginx来跑一下。
1)命令行php目录下键入 php-cgi.exe -b 127.0.0.1:9000 -c C:/wnmp/php7/php.ini(输入以后没有反应,但是不能关掉命令行)
2)命令行nginx目录下 start nginx
3)在www目录下新建一个phpinfo.php文件
<?php
phpinfo();
?>
4)浏览器中输入localhost/phpinfo.php,出现下面内容则说明php在nginx中运行成功了。
5)但是命令行手动启动php和nginx太麻烦了,写两个脚本“start_nginx.bat”和“stop_nginx.bat”,都放到nginx的根目录下去,再将上面下载的RunHiddenConsole.zip解压后的RunHiddenConsole.exe文件也放到该目录下。就可以双击start_nginx.bat和stop_nginx.bat文件来启动和关闭php和nginx啦。
start_nginx.bat内容如下
弄好后的文件放置如下:
遇到的问题:
1、PHP Startup: Unable to load dynamic library 'xxxx' 到指定的模块
解决办法:参考http://blog.csdn.net/u014299579/article/details/54944561
2、php启动因为找不到一个C++插件报的错误
解决办法:下载这个插件https://www.microsoft.com/zh-CN/download/details.aspx?id=48145