windows下配置nginx+php环境
来源:互联网 发布:mac ping ipv6地址 编辑:程序博客网 时间:2024/05/20 00:09
nginx相较于我们熟悉的apache、IIS的优势,就我浅入浅出的了解,在于“反向代理”和“负载均衡”。因此考虑到能够为Web服务器节省资源,它可以代替apache来提供Web服务。那么上正题了,nginx有这么多优势,那在windows下如何来配置nginx+php环境?网上看到还是那么多转载来转载去的文章。这里就我配置的过程,来介绍一下:
1、首先需要准备的应用程序包。
nginx:nginx/Windows-1.0.4
php:php-5.2.16-nts-Win32-VC6-x86.zip (nginx下php是以FastCGI的方式运行,所以我们下载非线程安全也就是nts的php包)
(还会用到)RunHiddenConsole:RunHiddenConsole.zip
2、安装与配置。
1)php的安装与配置。
直接解压下载好的php包,到D盘wnmp目录(D:\wnmp),这里把解压出来的文件夹重命名成php5。进入文件夹修改php.ini-recommended文件为php.ini,并用Editplus或者Notepad++打开来。找到
extension_dir = "./ext"
更改为
extension_dir = "D:/wnmp/php5/ext"
;extension=php_mysql.dll;extension=php_mysqli.dll
前面指定了php的ext路径后,只要把需要的扩展包前面所对应的“;”去掉,就可以了。这里打开php_mysql.dll和php_mysqli.dll,让php支持mysql。当然不要忘掉很重要的一步就是,把php5目录下的libmysql.dll文件复制到C:\Windows目录下,也可以在系统变量里面指定路径,当然这里我选择了更为方便的方法^_^。
到这里,php已经可以支持mysql了。
接下来我们来配置php,让php能够与nginx结合。找到
;cgi.fix_pathinfo=1
我们去掉这里的封号。
cgi.fix_pathinfo=1
2)nginx的安装与配置。
把下载好的nginx-1.0.4的包同样解压到D盘的wnmp目录下,并重命名为nginx。接下来,我们来配置nginx,让它能够和php协同工作。进入nginx的conf目录,打开nginx的配置文件nginx.conf,找到
location / { root html; #这里是站点的根目录 index index.html index.htm;}
将root html;改为root D:/wnmp/www;
再往下,找到
# 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;#}
先将前面的“#”去掉,同样将root html;改为root D:/wnmp/www;。再把标记为红色的/scripts改为“$document_root”,这里的“$document_root”就是指前面“root”所指的站点路径,这是改完后的:
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000#location ~ \.php$ { root D:/wnmp/www; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params;}
保存配置文件,就可以了。
nginx+php的环境就初步配置好了,来跑跑看。我们可以输入命令
来启动php,并手动启动nginx,当然也可以利用脚本来实现。
首先把下载好的RunHiddenConsole.zip包解压到nginx目录内,RunHiddenConsole.exe的作用是在执行完命令行脚本后可以自动关闭脚本,而从脚本中开启的进程不被关闭。然后来创建脚本,命名为“start_nginx.bat”,我们在Notepad++里来编辑它
@echo offREM Windows 下无效REM set PHP_FCGI_CHILDREN=5REM 每个进程处理的最大请求数,或设置为 Windows 环境变量set PHP_FCGI_MAX_REQUESTS=1000 echo Starting PHP FastCGI...RunHiddenConsole D:/wnmp/php5/php-cgi.exe -b 127.0.0.1:9000 -c D:/wnmp/php5/php.ini echo Starting nginx...RunHiddenConsole D:/wnmp/nginx/nginx.exe -p D:/wnmp/nginx
再另外创建一个名为stop_nginx.bat的脚本用来关闭nginx
@echo offecho Stopping nginx... taskkill /F /IM nginx.exe > nulecho Stopping PHP FastCGI...taskkill /F /IM php-cgi.exe > nulexit
做好后,是这样的
这样,我们的服务脚本也都创建完毕了。双击start_nginx.bat看看进程管理器是不是有两个nginx.exe的进程和一个php-cgi.exe的进程呢?
这样nginx服务就启动了,而且php也以fastCGI的方式运行了。
到站点目录下,新建一个phpinfo.php的文件,在里面编辑
<?php phpinfo();?>
保存后,打开浏览器输入“http://localhost/phpinfo.php”,如果看到
就说明,nginx+php的环境已经配置好了,呵呵~
- windows下配置nginx+php环境配置
- 配置Windows下Nginx + PHP 开发环境
- windows下安装配置nginx+php环境
- windows下配置nginx+php环境
- windows下配置nginx+php环境
- windows下配置nginx+php环境
- windows下配置nginx+php环境
- windows下配置nginx+php环境
- windows下配置nginx+php环境
- windows下配置nginx+php环境
- windows下配置nginx+php环境
- Windows下nginx+php环境的配置
- windows下配置nginx+php环境
- windows下配置nginx+php环境
- windows下配置nginx+php环境
- windows下配置nginx+php环境
- windows下配置nginx+php环境
- windows下配置nginx+php环境
- ethhdr、ether_header、iphdr、tcphdr、udphdr 结构介绍
- Extjs:ExtJs使用总结(非常详细)
- 互联网性能测试杂记
- volatile变量的使用条件
- C#读取oracle的number字段类型
- windows下配置nginx+php环境
- Intra-cluster Replication in Apache Kafka
- sencha touch之让tabPanel的tab居中
- 注册您的手机时错误。请重试。(错误代码:0x80004005)
- Sql Server数据库在表中输入null值的方法!(快捷键)
- Django学习笔记之【管理(admin)界面设置】
- zoj 2401
- Windows下的Memcache安装与测试教程
- Android linker 详解