在Unix/Linux安装FastCGI

犇骉 2011-01-24

在Unix/Linux安装FastCGI起来比较复杂。现在就在这里讲一下,在Unix/Linux系统下,Perl语言,Apache服务器环境下安装FastCGI。  

PERL的FCGI模块:  
1、首先我们安装FastCGI在Perl下的模块。最新版本在http://www.fastcgi.com
里下载。  
最新版本:FCGI-0.56.tar.gz  
2、下载   FCGI-0.45.tar.gz   并且解开  
$   gunzip   -c   FCGI-0.56.tar.gz   |   tar   xvf   -  
3、编译及安装    
$   perl   Makefile.PL    
$   make    
$   make   install    
4、测试    
$   cp   echo.fpl   {你www里Fastcgi所在目录}  
$   lynx   {你www里echo.fpl的地址}  

如果顺利的话,应该会看到如下的结果:    
FastCGI   echo   (Perl)    
Request   number   1    
No   data   from   standard   input.    
Request   environment:    

DOCUMENT_ROOT=/usr/local/apache/htdocs    
FCGI_ROLE=RESPONDER    
GATEWAY_INTERFACE=CGI/1.1    
HTTP_ACCEPT=text/html,   text/plain,   application/applefile,   application/
x-metamai    
l-patch,   sun-deskset-message,   mail-file,   default,   postscript-file,   aud
io-file,    
x-sun-attachment,   text/enriched,   text/richtext,   application/andrew-ins
et,   x-be2    
,   application/postscript,   message/external-body,   message/partial,   appl
ication/p    
gp,   application/pgp,   video/mpeg,   video/*,   image/*,   audio/*,   audio/mod,
  text/sgm    
l,   video/mpeg,   image/jpeg,   image/tiff,   image/x-rgb,   image/png,   image/x
-xbitmap,    
image/x-xbm,   image/gif,   application/postscript,   */*;q=0.01    
HTTP_ACCEPT_ENCODING=gzip,   compress    
HTTP_ACCEPT_LANGUAGE=en    
HTTP_HOST=localhost    
HTTP_NEGOTIATE=trans    
HTTP_USER_AGENT=Lynx/2.8.1pre.9   libwww-FM/2.14    
PATH=/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/usr/sbin:/opt/kde/bi
n:/home/m    
yhsu/bin:/usr/X11R6/bin:/usr/sbin:/opt/kde/bin:/usr/X11R6/bin:/usr/sbi
n:/opt/kd    
e/bin    
QUERY_STRING=    
REMOTE_ADDR=127.0.0.1    
REMOTE_PORT=1427    
REQUEST_METHOD=GET    
REQUEST_URI=/fcgi-bin/echo.fpl    
SCRIPT_FILENAME=/usr/local/www/fcgi-bin/echo.fpl    
SCRIPT_NAME=/fcgi-bin/echo.fpl    
SERVER_ADMIN=myhsu@localhost.localdomain    
SERVER_NAME=localhost.localdomain    
SERVER_PORT=80    
SERVER_PROTOCOL=HTTP/1.0    
SERVER_SIGNATURE=    

Apache/1.3.6   Server   at   localhost.localdomain   Port   80    
SERVER_SOFTWARE=Apache/1.3.6   (Unix)   mod_fastcgi/2.2.2    
UNIQUE_ID=N1VIbX8AAAEAAAQnKKo    
More   on   its   way   ...   wait   a   few   seconds    
Initial   environment:    

最后,给大家一个fastcgi编程的例子:  
#!/usr/local/bin/perl  
use   CGI::Fast;  

my   $counter   =   0;  

while   (my   $cgi   =   new   CGI::Fast)   {  
                print( "Content-type:   text/html\n\n ");  
                print( "We   have   served   $counter   requests ");  
                $counter++;  
}  


就这些了,

hoowa

相关推荐