windows下配置nginx+php环境

来源:互联网 发布:网络剧《余罪》 编辑:程序博客网 时间:2024/06/12 22:13

       nginx相较于我们熟悉的apache、IIS的优势,就我浅入浅出的了解,在于“反向代理”和“负载均衡”。因此考虑到能够为Web服务器节省资源,它可以代替apache来提供Web服务

1. 下载安装包

  • php7.1.2(本文用): 点此选择合适版本
  • nginx1.10.3(本文用): 点此选择合适版本
  • RunHiddenConsole: 点此下载

       为了方便nginx、php-cgi的开启与关闭,我们会使用脚本来操作,而RunHiddenConsole.exe的作用是在执行完命令行脚本后可以自动关闭脚本,而从脚本中开启的进程不被关闭

2. 安装php

       解压php zip包到D:\study\wnmp,本文重命名为php-7.1.2。

       环境变量配置这里就不多说了,参见百度经验

       进入文件夹,复制一个php.ini-development(或php.ini-production,个人认为这个现没什么区别,如有误,请在文中回复),改名为php.ini,打开(本文用notepad++),找到

extension_dir = “./ext”

改为

extension_dir = “D:/study/wnmp/php-7.1.2/ext”

分别找到

;extension=php_mysqli.dll

;cgi.fix_pathinfo=1

改为

extension=php_mysqli.dll

cgi.fix_pathinfo=1

3. 安装nginx

解压nginx到,D:\study\wnmp,重命名为nginx-1.10.3,进入conf目录,打开nginx.conf,找到

location / {        root   html;        index  index.html index.htm;}

改为(D:/study/wnmp/phpProject为本文的项目根目录)

location / {        root   D:/study/wnmp/phpProject;        index  index.html index.htm;}

找到

# 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;#}

改为

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000#location ~ \.php$ {    root           D:/study/wnmp/phpProject;    fastcgi_pass   127.0.0.1:9000;    fastcgi_index  index.php;    fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;    include        fastcgi_params;}

4. 配置脚本

把RunHiddenConsole.exe放到D:\study\wnmp\nginx-1.10.3目录下,创建脚本start_nginx.bat

@echo offREM Windows 下无效REM set PHP_FCGI_CHILDREN=5REM 每个进程处理的最大请求数,或设置为 Windows 环境变量set PHP_FCGI_MAX_REQUESTS=1000echo Starting PHP FastCGI...RunHiddenConsole D:/study/wnmp/php-7.1.2/php-cgi.exe -b 127.0.0.1:9000 -c D:/study/wnmp/php-7.1.2/php.iniecho Starting nginx...RunHiddenConsole D:/study/wnmp/nginx-1.10.3/nginx.exe -p D:/study/wnmp/nginx-1.10.3

创建脚本stop_nginx.bat

@echo offecho Stopping nginx...  taskkill /F /IM nginx.exe > nulecho Stopping PHP FastCGI...taskkill /F /IM php-cgi.exe > nulexit

运行start_nginx.bat,任务管理器出现如图所示进程,则正确,运行stop_nginx.bat,图中3个进程没了,则正确

进程图

打开start_nginx.bat,进入D:\study\wnmp\phpProject,新建文件phpinfo.php

<?php    phpinfo();?>

浏览器输入 http://localhost/phpinfo.php

phpinfo

0 0
原创粉丝点击