您好,欢迎访问一九零五行业门户网

介绍在IIS上配置php服务器

推荐(免费):iis
1、下载php解释器
地址为http://windows.php.net/download/
版本有两种,线程安全和非线程安全,线程安全是给apache用的,非线程安全是给iis用的,我们要配的是iis,所以下载非线程安全的,x86和x64看自己的机器是什么系统选择对应的版本下载就行了。
2、安装php解释器
php可以说不用安装的,只要将文件解压到c:\php(一般不放在系统盘,那么就放e:\php)文件夹,就算安装完成了。
3、配置php.ini
拷贝php.ini-development,改名为php.ini,并进行如下修改:
f35d6e602fd7d0f0edfa6f7d103c1b57扩展插件的路径
; directory in which the loadable extensions (modules) reside.; http://php.net/extension-dir; extension_dir = "./"; on windows: extension_dir = "c:\php\ext"
修改最后一行,填入自己真实的php解释器地址,以及后面跟着ext文件夹,这个里面放的都是插件
<2>设置要引入哪些插件
; windows extensions; note that odbc support is built in, so no dll is needed for it.; note that many dll files are located in the extensions/ (php 4) ext/ (php 5); extension folders as well as the separate pecl dll download (php 5).; be sure to appropriately set the extension_dir directive.;;extension=php_bz2.dll;extension=php_curl.dll;extension=php_fileinfo.dll;extension=php_gd2.dll;extension=php_gettext.dll;extension=php_gmp.dll;extension=php_intl.dll;extension=php_imap.dll;extension=php_interbase.dll;extension=php_ldap.dllextension=php_mbstring.dll;extension=php_exif.dll ; must be after mbstring as it depends on itextension=php_mysql.dllextension=php_mysqli.dll;extension=php_oci8_12c.dll ; use with oracle database 12c instant client;extension=php_openssl.dll;extension=php_pdo_firebird.dll;extension=php_pdo_mysql.dll;extension=php_pdo_oci.dll;extension=php_pdo_odbc.dll;extension=php_pdo_pgsql.dll;extension=php_pdo_sqlite.dll;extension=php_pgsql.dll;extension=php_shmop.dll
要引入的插件,只要把前面的分号去掉就可以了,我这里只引入了mysql、mysqli、mbstring。
<3>设置时区
[date]; defines the default timezone used by the date functions; http://php.net/date.timezonedate.timezone = asia/shanghai
<4>支持短标签
; this directive determines whether or not php will recognize code between; <? and ?> tags as php source which should be processed as such. it is; generally recommended that <?php and ?> should be used and that this feature; should be disabled, as enabling it may result in issues when generating xml; documents, however this remains supported for backward compatibility reasons.; note that this directive does not control the <?= shorthand tag, which can be; used regardless of this directive.; default value: on; development value: off; production value: off; http://php.net/short-open-tagshort_open_tag = on
<5>启用fastcgi
; fastcgi under iis (on winnt based os) supports the ability to impersonate; security tokens of the calling client. this allows iis to define the; security context that the request runs under. mod_fastcgi under apache; does not currently support this feature (03/17/2002); set to 1 if running under iis. default is zero.; http://php.net/fastcgi.impersonatefastcgi.impersonate = 1
<6>cgi相关设置pathinfo
; cgi.fix_pathinfo provides *real* path_info/path_translated support for cgi. php's; previous behaviour was to set path_translated to script_filename, and to not grok; what path_info is. for more information on path_info, see the cgi specs. setting; this to 1 will cause php cgi to fix its paths to conform to the spec. a setting; of zero causes php to behave as before. default is 1. you should fix your scripts; to use script_filename rather than path_translated.; http://php.net/cgi.fix-pathinfocgi.fix_pathinfo=1
<7>cgi相关设置redirect
; cgi.force_redirect is necessary to provide security running php as a cgi under; most web servers. left undefined, php turns this on by default. you can; turn it off here at your own risk; **you can safely turn this off for iis, in fact, you must.**; http://php.net/cgi.force-redirectcgi.force_redirect = 0
<8>session存储路径
; where mode is the octal representation of the mode. note that this; does not overwrite the process's umask.; http://php.net/session.save-pathsession.save_path = "d:\server\web\session"
<9>数据库
mysql.default_port = 3306
mysql.default_host = localhost
mysql.default_user = root
<10>输出缓存
; note: this directive is hardcoded to off for the cli sapi; default value: off; development value: 4096; production value: 4096; http://php.net/output-bufferingoutput_buffering = on//这里应该是填一个值,比如4096
<11>限定上传文件体积最大值
upload_max_filesize = 100m
<12>隐藏php版本
把on改为off,在header里就不会显示php版本
expose_php = off
4、将php.ini放到系统目录
配置完成之后,将php.ini拷贝一份放到c:\windows下。注意,如果是win7使用的iis7已经不需要这么做了。
5、配置iis(iis默认已经安装完毕,此处不再介绍如何安装iis)
<1>处理程序映射(handlermappings)
都点击确定之后,会弹出一个警告对话框,点击“是”就可以了。
注意:一开始可能没有fastcgimodule这个模块。要从打开或关闭windows功能-web服务器iis-添加角色服务-勾选cgi进行安装。
<2>isapi和cgi限制
<3>添加站点
在某个路径下创建一个文件夹,在iis中添加站点,将此文件夹作为站点添加进去
注意,添加站点之后,要对其添加everyone用户,给予全部权限。
<4>设置站点默认页面
<5>添加默认页面
在网站的根目录创建一个名为index.php的文件,在内容中输入
<?php phpinfo(); ?>
<6>打开网站
配置hosts指向,将刚才配置的网站域名指向127.0.0.1,像这样:
127.0.0.1 yourdomain.com
浏览器打开yourdomain.com,可以看到成功解析了index.php文件,显示的是php的相关信息。
有可能出现的错误:访问可能出现“fastcgi进程意外退出500错误”。默认已经有一个网站占用了所有端口,现在我们又添加一个网站可能导致冲突,把默认那个网站停止就可以了。
6、集成codeigniter框架
<1>下载codeigniter
下载地址:http://codeigniter.org.cn/
<2>整合codeigniter
解压之后,打开codeigniter文件夹,将里面的内容复制粘贴到站点的根目录,会提示是否替换掉原来的index.php文件,选择"是",这样框架就算整合完毕了
打开浏览器访问主页,看到的是codeigniter框架的提示信息!
<3>添加favicon图标
每个page都会自动去加载favicon图标,因此应该在index.php目录下放置favicon.ico文件,不然都会报错,显示找不到图标。
7、有可能出现的问题
<1>丢失 msvcr110.dll
第一次访问php网站可能会出现“无法启动此程序,因为计算机中丢失 msvcr110.dll”的错误,应该这样解决:
-打开微软下载页面:http://www.microsoft.com/zh-cn/download/details.aspx?id=30679
-点击下载
-选择相应的版本,64就选64,32就选32
-点击下载
-安装
完成之后网站就可以正常访问了。
<2>唯一密钥属性“value”设置…无法添加类型为add
在web.config-files节点改为:
<files> <clear /> <add value="index.php" /> <add value="index.html" /> </files>
5bdf4c78156c7953567bb5a0aef2fc53服务器部署中常见问题
服务器碰见了一些问题 ,一个就是上面说的value属性,value设置好之后就是cgi问题,没有权限之类的,把php引擎的文件夹设置everyone之后,发现cgi意外退出,直接打开cgi,发现原来是丢失 msvcr110.dll,把丢失 msvcr110.dll装上之后好了。
注意,因为把system和application文件夹移到web目录以外,但是程序在访问的时候仍然会访问到这两个文件夹,因此也要把这两个文件夹添加everyone。
23889872c2e8594e0f446a471a78ec4c升级php7遇到的问题
升级php7传说中性能可以提升很多倍。php5竟然是10多年前的产物...
配置php.ini没碰到什么问题,主要一个是mysql.dll的选项没了,配置数据库的port、username等都不是mysql而是mysqli,这些我就没弄了,在ci里面会有配置,应该没什么大问题。
开始运行,cgi异常。直接打开cgi发现报错:丢失vcruntime140.dll。这个错误是因为最新版的php7(php7.1)需要安装visual c++redistributable 2015。
下载地址:https://www.microsoft.com/en-us/download/details.aspx?id=48145,下载安装就好了。
43ad812d3a971134e40facaca816c822最便捷的解决方案
今天调试刚买的服务器,发现无论怎么弄都会报fastcgi错误,错误代码是***0005,即5号代码的错误。怎么弄都不行,一度怀疑此云服务器的fastcgimodule被阉割了,不能正常运行。
直到找到了这样一个解决方案,https://php.iis.net,可以在线安装。踏破铁鞋无觅处,得来全不费功夫。
8、在本地配置https
本地测试为了可以跟线上一致,以https来测试,必须要配置ssl证书。
以上就是介绍在iis上配置php服务器的详细内容。
其它类似信息

推荐信息