win10+nginx+php7+mysql

来源:互联网 发布:生物数据分析软件 编辑:程序博客网 时间:2024/04/28 00:34

本文参考了 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
  1.   
[html] view plain copy
  1. ; On windows:  
  2. extension_dir = "./txt"  

改为

[html] view plain copy
  1. ; On windows:  
  2. extension_dir = "C:\wnmp\php7\ext"  

将下面两个扩展前面的“;”去掉。(因为php7不支持MySQL扩展了,所以这里只有mysqli和pdo扩展)

[html] view plain copy
  1. ;extension=php_mysqli.dll  
  2. ;extension=php_pdo_mysql.dll  

最后让PHP支持nginx,将下面一行前面的“;”去掉。

[html] view plain copy
  1. ;cgi.fix_pathinfo=1  


2)nginx安装与配置。

先在C:/wnmp目录下新建一个www文件夹,作为服务器的根目录。

将下载好的nginx包文件解压到C:\wnmp目录下,重命名为nginx。打开nginx\conf下的nginx.conf文件来配置nginx。

[html] view plain copy
  1. location/ {  
  2. root html;  
  3. index index.html index.htm;  
  4. }  
改为

[html] view plain copy
  1. location/ {  
  2. root C:/wnmp/www; #将站点的根目录定位到C:/wnmp/www  
  3. index index.html index.htm;  
  4. }  

再将

[html] view plain copy
  1. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000  
  2. #  
  3. #location ~ \.php$ {  
  4. # root html;  
  5. # fastcgi_pass 127.0.0.1:9000;  
  6. # fastcgi_index index.php;  
  7. # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;  
  8. # include fastcgi_params;  
  9. #}  

改为

[html] view plain copy
  1. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000  
  2. #  
  3. location ~ \.php$ {  
  4.     root           C:/wnmp/www;  
  5.     fastcgi_pass   localhost:9000;  
  6.     fastcgi_index  index.php;  
  7.       
  8.     # 这里$document_root指的是上面定义好的nginx根目录:C:/wnmp/www  
  9.     fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;  
  10.     include        fastcgi_params;  
  11. }  
保存好配置即可。


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内容如下

[html] view plain copy
  1. @echo off  
  2. REM Windows 下无效  
  3. REM set PHP_FCGI_CHILDREN=5  
  4.   
  5. REM 每个进程处理的最大请求数,或设置为 Windows 环境变量  
  6. set PHP_FCGI_MAX_REQUESTS=1000  
  7.    
  8. echo Starting PHP FastCGI...  
  9. RunHiddenConsole C:/wnmp/php7/php-cgi.exe -b 127.0.0.1:9000 -c C:/wnmp/php7/php.ini  
  10.    
  11. echo Starting nginx...  
  12. RunHiddenConsole C:/wnmp/nginx/nginx.exe -p C:/wnmp/nginx  
stop_ngin.bat内容如下
[html] view plain copy
  1. @echo off  
  2. echo Stopping nginx...    
  3. taskkill /F /IM nginx.exe > nul  
  4. echo Stopping PHP FastCGI...  
  5. taskkill /F /IM php-cgi.exe > nul  
  6. 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


原创粉丝点击