php FastCGI ISAPI win2003 iis6 20090214更新(精典)

[ 2012-09-19 09:56:13 | 作者: admin ]
字号: | |
【准备工作】
下载相关软件
PHP 5.2.6 zip package
http://www.php.net/releases/

Zend Optimizer v3.3.3
http://downloads.phpchina.com/zend/optimizer/

eAccelerator 0953 for PHP 5.2.6
http://www.sitebuddy.com/PHP/Accelerators/eAccelerator_windows_binaries_builds

ISAPI_Rewrite3_0058_manual.exe 手工安装
http://www.helicontech.com/download-isapi_rewrite3.htm

mysql5.0.67 Without installer (unzip in C:\)
http://dev.mysql.com/downloads/mysql/5.0.html

FastCGI6.1.36.1
http://www.iis.net/downloads/default.aspx?tabid=34&g=6&i=1521

Zend Optimizer没有zip包,需要先本地安装一下解压出ZendOptimizer.dll备用。

解压php到d:/php,设置权限(除Administrators和SYSTEM外一般与IUSR_计算机名,IWAM_计算机名,IIS_WPG,NETWORK SERVICE,Users中的一个或多个有关)可先设置Everyone完全控制,调试成功后再做处理。限制为GET,HEAD,POST,TRACE。php.ini中的一些设置如下:

output_buffering = On
disable_functions = system,passthru,shell_exec,exec,popen,proc_open
enable_dl = Off

upload_tmp_dir = "D:/tmp/uploadtemp/"
session.save_path = "d:/tmp/sessiondata/"
date.timezone = "Etc/GMT-8" ;表示的是 GMT+8
mbstring.language = Neutral ; Set default language to Neutral(UTF-8) (default)
mbstring.internal_encoding = UTF-8 ; Set internal encoding to UTF-8


cgi.force_redirect = 0
cgi.fix_pathinfo = 1
fastcgi.impersonate = 1

[eaccelerator]
zend_extension_ts="D:/Zend/eAccelerator/eAccelerator0953_5.2.6.dll"
eaccelerator.shm_size="64"
eaccelerator.cache_dir="d:/tmp/eaccelerator"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.log_file="d:/tmp/eaccelerator"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="300"
eaccelerator.shm_prune_period="120"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"
eaccelerator.keys="shm"
eaccelerator.sessions="shm"
[Zend]
zend_optimizer.optimization_level=1023
zend_optimizer.encoder_loader=0
zend_extension_ts="D:/Zend/ZendOptimizer-3.3.3/lib/Optimizer-3.3.3/php-5.2.x/ZendOptimizer.dll"

【MYSQL】

解压mysql到d:\mysql,编辑my.ini

[mysqld]
port=3306
basedir="D:/mysql/"
datadir="D:/mysql/Data/"
tmpdir="d:/mysql/tmp/"
default-character-set=utf8
default-storage-engine=MYISAM
skip-bdb
skip-innodb
skip-locking

key_buffer=16M
max_allowed_packet=1M
table_cache=128
thread_cache=8
join_buffer_size=512K
sort_buffer=512K
record_buffer=512K
max_connections=500
wait_timeout=120
interactive_timeout=120
max_connect_errors=3000
long_query_time=1
max_heap_table_size=16M
tmp_table_size=8M
thread_concurrency=8
myisam_sort_buffer_size=8M
myisam_sort_buffer_size=4M
low_priority_updates=1
ft_min_word_len=1
编辑两个批处理
安装
d:
cd D:\mysql\bin
mysqld-nt.exe --install MySQL --defaults-file=D:\mysql\my.ini
net start mysql
pause
卸载
d:
cd D:\APM\mysql\bin
net stop mysql
mysqld-nt.exe --remove MySQL
pause

【ISAPI PHP】
添加环境变量 PHPRC=D:\PHP 这个是通知iis读取php.ini文件的路径。
在PATH中加入 D:\PHP 能读取相关动态链接库。
添加一个新的web服务扩展 php d:\php\php5isapi.dll
添加应用程序扩展名映射 可执行文件 d:\php\php5isapi.dll 扩展名.php
重启IIS php就可以用了。


【FastCGI PHP】
这个不用添加环境变量和修改PATH变量。
先安装FastCGI,安装程序会自动添加
Web 服务扩展 - FastCGI Handler
c:\windows\system32\inetsrv\fcgiext.dll
并设置为允许。
修改c:\windows\system32\inetsrv\fcgiext.ini

[Types]
php=PHP
[PHP]
ExePath=D:\php\php-cgi.exe
InstanceMaxRequests=10000
EnvironmentVars=PHP_FCGI_MAX_REQUESTS:10000

添加应用程序扩展名映射 可执行文件 c:\windows\system32\inetsrv\fcgiext.dll 扩展名.php
重启iis就行了。

PHP Security Recommendations
The following settings can be used to tighten the security of a PHP installation. To make the recommended changes locate and open the php.ini file and edit the configuration settings as described below:

Setting Description allow_url_fopen=Off
allow_url_include=Off Disable remote URLs for file handling functions, which may cause code injection vulnerabilities. register_globals=Off Disable register_globals. open_basedir="c:\inetpub\" Restrict where PHP processes can read and write on a file system. safe_mode=Off
safe_mode_gid=Off Disable safe mode max_execution_time=30
max_input_time=60 Limit script execution time memory_limit=16M
upload_max_filesize=2M
post_max_size=8M
max_input_nesting_levels=64 Limit memory usage and file sizes display_errors=Off
log_errors=On
error_log="C:\path\of\your\choice" Configure error messages and logging fastcgi.logging=0 IIS FastCGI module will fail the request when PHP sends any data on stderr by using FastCGI protocol. Disabling FastCGI logging will prevent PHP from sending error information over stderr, and generating 500 response codes for the client. expose_php=Off Hide presence of PHP

FastCGI大大加强了IIS处理PHP的能力,能迅速提高PHP站点的反应速度和生产力,并具有更高的稳定性和安全性.

======================================================
用<?php phpinfo();?>显示 两者的运行模式的区别
Server API CGI/FastCGI
Server API ISAPI

之前转载的一篇文章说使用PHP 5.2.6 Non-thread-safe zip package
《在IIS6上使用FastCGI PHP5(应该是目前Win性能最好的PHP支持方法)》
http://hi.baidu.com/surgefree/blog/item/0804882bbaeb8effe7cd406a.html

但是始终无法加载Zend Optimizer,现在很多商业php程序都加密了,不加载这个东西是不行的。 但线程安全版本是可以加载的。

在使用isapi的时候经常出现
事件类型: 错误
事件来源: Zend Optimizer
事件种类: 无
事件 ID: 487
日期: xxxx-x-x
事件: x:xx:xx
用户: N/A
计算机: xxxxxx
描述:
事件 ID ( 487 )的描述(在资源( Zend Optimizer )中)无法找到。本地计算机可能没有必要的注册信息或消息 DLL 文件来从远程计算机显示消息。您可能可以使用 /AUXSOURCE= 标识来检索词描述;查看帮助和支持以了解详细信息。下列信息是事件的一部分: Unable to view file mapping, 试图访问无效的地址。

fastcgi应该不会出现类似的问题。

IIS6.0以FastCGI模式加载php环境的测试
http://www.butian.org/knowledge/network/720.html

FastCGI PHP参考文章
Using FastCGI to Host PHP Applications on IIS 6.0
http://learn.iis.net/page.aspx/247/using-fastcgi-to-host-php-applications-on-iis-60/
No Zend Optimizer when using --disable-zts
http://forums.iis.net/t/1073763.aspx

http://www.fastcgi.com

http://learn.iis.net/page.aspx/246/using-fastcgi-to-host-php-applications-on-iis-70/

为什么要使用线程安全版本呢?这里有一篇参考文章的留言里

Why use thread safe php with FastCGI
Submitted by Anonymous on Thu, 2008-11-13 03:50.

Just curious. Why would you use thread safe PHP with FastCGI? Did you test with non thread safe PHP with eA? The whole idea I thought was that FastCGI would allow you to run non thread safe PHP code safely the way PHP was originally written, but handle it in a way that is much faster than CGI every could.

reply
No stable non-thread safe Opcode caches
Submitted by Brashquido on Fri, 2008-11-14 16:05.

In a nutshell, there are no open source non-thread safe opcode caches that run on Windows/IIS (EA, APC, xCache, etc). Long story short there are some design flaws in all of the open source opcode caches where they have all been designed more or less only to work on a *nix/Apache platform.

There is no harm in using thread safe binaries with FastCGI, it just isn't ideal. Have a read through this article for further details. I don't expect this issue to be fixed any time soon.




http://hi.baidu.com/vkejzrhjjwbmxzq/item/5b6062a430e437a928ce9d60
[最后修改由 admin, 于 2016-08-17 11:04:43]
评论Feed 评论Feed: http://blog.xg98.com/feed.asp?q=comment&id=1876

这篇日志没有评论。

此日志不可发表评论。