千万个美丽的未来,抵不上一个温暖的现在,每一个真实的现在,都是我们曾经幻想的未来!
Mar
13
具体配置文件参考:
fastcgi.conf
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
fastcgi_param PATH_INFO $path_info;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
#fastcgi_param REDIRECT_STATUS 200;
nginx.conf
user nginx nginx;
worker_processes 16;
error_log logs/nginx_error.log crit;
pid logs/nginx.pid;
events {
worker_connections 65535;
}
http {
include mime.types;
default_type application/octet-stream;
log_format weblog '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log logs/access.log weblog;
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_proxied any;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
include /usr/local/nginx/conf/test.conf;
}
test.conf
server
{
listen 80;
server_name www.test.com;
access_log logs/test.log;
root /home/wwwroot/ci;
index index.php index.html index.htm;
location / {
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php/$1 last;
}
}
location ~ \.php {
set $real_script_name $fastcgi_script_name;
set $path_info "";
if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)
set $real_script_name $1;
set $path_info $2;
}
fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
include fastcgi.conf;
}
}
以上配置可以支持ThinkPHP,CI,ZF等等框架
下面是NGINX官方对于pathinfo提供的解决方法:
fastcgi_split_path_info
syntax: fastcgi_split_path_info regex
context: location
version: ≥ 0.7.31
This directive allows the setting of the SCRIPT_FILENAME (SCRIPT_NAME) and PATH_INFO variables of the CGI specification. The regex consists of two groups:
path to the script that will handle the request — corresponding to $fastcgi_script_name.
the value of the parameter to be given to the script — corresponding to the $fastcgi_path_info.
Here's an example. The script show.php receives as argument the string article/0001. The following configuration will handle path splitting properly:
location ~ ^.+\.php {
(...)
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME /path/to/php$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
(...)
}
Requesting /show.php/article/0001 sets SCRIPT_FILENAME to /path/to/php/show.php and PATH_INFO to /article/0001.
fastcgi.conf
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
fastcgi_param PATH_INFO $path_info;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
#fastcgi_param REDIRECT_STATUS 200;
nginx.conf
user nginx nginx;
worker_processes 16;
error_log logs/nginx_error.log crit;
pid logs/nginx.pid;
events {
worker_connections 65535;
}
http {
include mime.types;
default_type application/octet-stream;
log_format weblog '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log logs/access.log weblog;
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_proxied any;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
include /usr/local/nginx/conf/test.conf;
}
test.conf
server
{
listen 80;
server_name www.test.com;
access_log logs/test.log;
root /home/wwwroot/ci;
index index.php index.html index.htm;
location / {
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php/$1 last;
}
}
location ~ \.php {
set $real_script_name $fastcgi_script_name;
set $path_info "";
if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)
set $real_script_name $1;
set $path_info $2;
}
fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
include fastcgi.conf;
}
}
以上配置可以支持ThinkPHP,CI,ZF等等框架
下面是NGINX官方对于pathinfo提供的解决方法:
fastcgi_split_path_info
syntax: fastcgi_split_path_info regex
context: location
version: ≥ 0.7.31
This directive allows the setting of the SCRIPT_FILENAME (SCRIPT_NAME) and PATH_INFO variables of the CGI specification. The regex consists of two groups:
path to the script that will handle the request — corresponding to $fastcgi_script_name.
the value of the parameter to be given to the script — corresponding to the $fastcgi_path_info.
Here's an example. The script show.php receives as argument the string article/0001. The following configuration will handle path splitting properly:
location ~ ^.+\.php {
(...)
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME /path/to/php$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
(...)
}
Requesting /show.php/article/0001 sets SCRIPT_FILENAME to /path/to/php/show.php and PATH_INFO to /article/0001.
May
2
方法:系统平台是CentOS 5,前提是LAMP已配置好,运行正常。
1. wget -c http://www.21andy.com/centos/5/i386/spawn-fcgi-1.6.3-1.el5.i386.rpm(也可以去官方下载源码包编译安装:http://www.lighttpd.net/download/spawn-fcgi-1.6.3.tar.gz)
2. rpm -ivh spawn-fcgi-1.6.3-1.el5.i386.rpm
3. 使用spawn-fcgi来控制php-cgi的FastCGI进程:
/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 5 -u apache -g apache -f /usr/bin/php-cgi
参数含义如下:
-f 指定调用FastCGI的进程的执行程序位置,根据系统上所装的PHP的情况具体设置。
-a 绑定到地址addr。
-p 绑定到端口port。
-s 绑定到unix socket的路径path。
-C 指定产生的FastCGI的进程数,默认为5。(仅用于PHP)
-P 指定产生的进程的PID文件路径。
-u和-g FastCGI使用什么身份(-u 用户 -g 用户组)运行,CentOS下可以使用apache用户,其他的根据情况配置,如nobody、www-data等。
4. 将这行代码加入到/etc/rc.local文件底部,这样系统启动的时候就可以同时启动PHP的FastCGI进程。
1. wget -c http://www.21andy.com/centos/5/i386/spawn-fcgi-1.6.3-1.el5.i386.rpm(也可以去官方下载源码包编译安装:http://www.lighttpd.net/download/spawn-fcgi-1.6.3.tar.gz)
2. rpm -ivh spawn-fcgi-1.6.3-1.el5.i386.rpm
3. 使用spawn-fcgi来控制php-cgi的FastCGI进程:
/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 5 -u apache -g apache -f /usr/bin/php-cgi
参数含义如下:
-f
-a
-p
-s
-C
-P
-u和-g FastCGI使用什么身份(-u 用户 -g 用户组)运行,CentOS下可以使用apache用户,其他的根据情况配置,如nobody、www-data等。
4. 将这行代码加入到/etc/rc.local文件底部,这样系统启动的时候就可以同时启动PHP的FastCGI进程。
Nov
30
1、右键“计算机”,点击“管理”
2、添加角色
3、添加角色服务
如果你的程序在IIS7下出错,记得选择服务的时候添加IIS6兼容模块,如果无问题,这个可以不用选择;
4、打开“处理程序映射”
选择“添加模块映射”,添加你PHP目录中的php-cgi;
5、选择fastcgi配置(注意,这里如果是IIS7,则需要手动安装Administration Pack for IIS 7.0 ,如果是IIS7.5,则无需下载,IIS7.5已经集成此功能);
点击“Edit.。.”,则弹出如下图:
添加:PHP_FCGI_MAX_REQUESTS , value 数值10000;
进入你PHP的存放目录,复制一份php.ini-disk,改名为php.ini;
fastcgi.impersonate = 1
cgi.fix_pathinfo=1
cgi.force_redirect = 0
以上3个前的;去掉,并修改以上相应数值,如下图所示:
这样就可以完整的运行PHP了,可以用
<?php phpinfo();?>
测试是否正常;
以上PHP的配置,只是配置以fastcgi模式运行php,其他详细PHP.INI的配置跟原来IIS6中isapi的一样,可以照搬,网上教程一大把,我就不废话了。
2、添加角色
3、添加角色服务
如果你的程序在IIS7下出错,记得选择服务的时候添加IIS6兼容模块,如果无问题,这个可以不用选择;
4、打开“处理程序映射”
选择“添加模块映射”,添加你PHP目录中的php-cgi;
5、选择fastcgi配置(注意,这里如果是IIS7,则需要手动安装Administration Pack for IIS 7.0 ,如果是IIS7.5,则无需下载,IIS7.5已经集成此功能);
点击“Edit.。.”,则弹出如下图:
添加:PHP_FCGI_MAX_REQUESTS , value 数值10000;
进入你PHP的存放目录,复制一份php.ini-disk,改名为php.ini;
fastcgi.impersonate = 1
cgi.fix_pathinfo=1
cgi.force_redirect = 0
以上3个前的;去掉,并修改以上相应数值,如下图所示:
这样就可以完整的运行PHP了,可以用
<?php phpinfo();?>
测试是否正常;
以上PHP的配置,只是配置以fastcgi模式运行php,其他详细PHP.INI的配置跟原来IIS6中isapi的一样,可以照搬,网上教程一大把,我就不废话了。
Feb
23
在IIS6上使用FastCGI PHP5(应该是目前Win性能最好的PHP支持方法)
1.下载FastCGI For IIS6
http://www.microsoft.com/downloads/details.aspx?FamilyID=2d481579-9a7c-4632-b6e6-dee9097f9dc5&displaylang=en
下载之后,双击运行进行安装即可. 安装后C:\WINDOWS\system32\inetsrv目录下有这几个文件
2、下载PHP5免安装版本,
http://www.php.net/downloads
解压到C:\PHP目录下
要确保IIS启动帐号对C:\PHP\*有读取执行权限
3、注册PHP到FastCGI
cscript fcgiconfig.js -add -section:"PHP" -extension:php -path:"C:\PHP\php-cgi.exe"
4、做一些性能和安全设置
C:\PHP\php.ini-recommended重命名为为C:\PHP\php.ini
打开C:\PHP\php.ini,修改:
extension_dir = "C:\PHP\ext"
fastcgi.impersonate = 1
cgi.fix_pathinfo=1
cgi.force_redirect = 0
执行:
cscript fcgiconfig.js -set -section:"PHP" -InstanceMaxRequests:10000
cscript fcgiconfig.js -set -section:"PHP" -EnvironmentVars:PHP_FCGI_MAX_REQUESTS:10000
以上两项设置最大池和响应连接数,可以根据自己的硬件配置、使用情况修改
5:配置 IIS & PHP
开始,运行,inetmgr依次展开,选中要配置的站点,右键,属性。切换到“主目录”选项卡,“配置”,“添加”,“浏览” 选中 C:\WINDOWS\system32\inetsrv\fcgiext.dll ,“确定”扩展名填入“.php”,勾选“脚本引擎”及“检查文件是否存在”,确定。
一切完毕之后重启IIS,赶紧写一个测试页试一下吧.
重启IIS后,打开测试页出现如下提示:
FastCGI Error
The FastCGI Handler was unable to process the request.
--------------------------------------------------------------------------------
Error Details:
Error Number: 5 (0x80070005).
Error Description: 拒绝访问。
HTTP Error 500 - Server Error.
Internet Information Services (IIS)
这个错误是由于在解压PHP之后,没有对IIS启动帐户赋予该目录的读取和运行权限.修改文件夹安全属性,问题可以解决.
第二种简单的方法就是:
打开C:\WINDOWS\system32\inetsrv\fcgiext.ini 在[Types]下面加上下面这几行
如果你的系统是windows server 2003 SP2的话安装好FastCGI之后WEB服务扩展里面就有FastCGI Handler的扩展了,
在你把上面的几行保存到fcgiext.ini之后,重启IIS就可以了,ISAPI扩展不用你添加就自动添加好了。
1.下载FastCGI For IIS6
http://www.microsoft.com/downloads/details.aspx?FamilyID=2d481579-9a7c-4632-b6e6-dee9097f9dc5&displaylang=en
下载之后,双击运行进行安装即可. 安装后C:\WINDOWS\system32\inetsrv目录下有这几个文件
2、下载PHP5免安装版本,
http://www.php.net/downloads
解压到C:\PHP目录下
要确保IIS启动帐号对C:\PHP\*有读取执行权限
3、注册PHP到FastCGI
cscript fcgiconfig.js -add -section:"PHP" -extension:php -path:"C:\PHP\php-cgi.exe"
4、做一些性能和安全设置
C:\PHP\php.ini-recommended重命名为为C:\PHP\php.ini
打开C:\PHP\php.ini,修改:
extension_dir = "C:\PHP\ext"
fastcgi.impersonate = 1
cgi.fix_pathinfo=1
cgi.force_redirect = 0
执行:
cscript fcgiconfig.js -set -section:"PHP" -InstanceMaxRequests:10000
cscript fcgiconfig.js -set -section:"PHP" -EnvironmentVars:PHP_FCGI_MAX_REQUESTS:10000
以上两项设置最大池和响应连接数,可以根据自己的硬件配置、使用情况修改
5:配置 IIS & PHP
开始,运行,inetmgr依次展开,选中要配置的站点,右键,属性。切换到“主目录”选项卡,“配置”,“添加”,“浏览” 选中 C:\WINDOWS\system32\inetsrv\fcgiext.dll ,“确定”扩展名填入“.php”,勾选“脚本引擎”及“检查文件是否存在”,确定。
一切完毕之后重启IIS,赶紧写一个测试页试一下吧.
重启IIS后,打开测试页出现如下提示:
FastCGI Error
The FastCGI Handler was unable to process the request.
--------------------------------------------------------------------------------
Error Details:
Error Number: 5 (0x80070005).
Error Description: 拒绝访问。
HTTP Error 500 - Server Error.
Internet Information Services (IIS)
这个错误是由于在解压PHP之后,没有对IIS启动帐户赋予该目录的读取和运行权限.修改文件夹安全属性,问题可以解决.
第二种简单的方法就是:
打开C:\WINDOWS\system32\inetsrv\fcgiext.ini 在[Types]下面加上下面这几行
引用
php=PHP
[PHP]
ExePath=C:\php\php-cgi.exe
InstanceMaxRequests=500
EnvironmentVars=PHP_FCGI_MAX_REQUESTS:10000
[PHP]
ExePath=C:\php\php-cgi.exe
InstanceMaxRequests=500
EnvironmentVars=PHP_FCGI_MAX_REQUESTS:10000
如果你的系统是windows server 2003 SP2的话安装好FastCGI之后WEB服务扩展里面就有FastCGI Handler的扩展了,
在你把上面的几行保存到fcgiext.ini之后,重启IIS就可以了,ISAPI扩展不用你添加就自动添加好了。