win10+nginx+php7+mysql
本文参考了 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,用文本编辑器将它打开。
将里面的
[html] view plain copy- ; On windows:
- extension_dir = "./txt"
改为
[html] view plain copy- ; On windows:
- extension_dir = "C:wnmpphp7ext"
将下面两个扩展前面的“;”去掉。(因为php7不支持MySQL扩展了,所以这里只有mysqli和pdo扩展)
[html] view plain copy
- ;extension=php_mysqli.dll
- ;extension=php_pdo_mysql.dll
最后让PHP支持nginx,将下面一行前面的“;”去掉。
[html] view plain copy
- ;cgi.fix_pathinfo=1
2)nginx安装与配置。
先在C:/wnmp目录下新建一个www文件夹,作为服务器的根目录。
将下载好的nginx包文件解压到C:wnmp目录下,重命名为nginx。打开nginxconf下的nginx.conf文件来配置nginx。
将
[html] view plain copy- location/ {
- root html;
- index index.html index.htm;
- }
[html] view plain copy
- location/ {
- root C:/wnmp/www; #将站点的根目录定位到C:/wnmp/www
- index index.html index.htm;
- }
再将
[html] view plain copy
- # 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 /scripts$fastcgi_script_name;
- # include fastcgi_params;
- #}
改为
[html] view plain copy- # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
- #
- location ~ .php$ {
- root C:/wnmp/www;
- fastcgi_pass localhost:9000;
- fastcgi_index index.php;
- # 这里$document_root指的是上面定义好的nginx根目录:C:/wnmp/www
- fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
- include fastcgi_params;
- }
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内容如下
- @echo off
- REM Windows 下无效
- REM set PHP_FCGI_CHILDREN=5
- REM 每个进程处理的最大请求数,或设置为 Windows 环境变量
- set PHP_FCGI_MAX_REQUESTS=1000
- echo Starting PHP FastCGI...
- RunHiddenConsole C:/wnmp/php7/php-cgi.exe -b 127.0.0.1:9000 -c C:/wnmp/php7/php.ini
- echo Starting nginx...
- RunHiddenConsole C:/wnmp/nginx/nginx.exe -p C:/wnmp/nginx
[html] view plain copy
- @echo off
- echo Stopping nginx...
- taskkill /F /IM nginx.exe > nul
- echo Stopping PHP FastCGI...
- taskkill /F /IM php-cgi.exe > nul
- exit
弄好后的文件放置如下:
遇到的问题:
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