在UNIX/Linux下安装FastCGI的方式

发表于:2007-07-04来源:作者:点击数: 标签:
在 Unix / Linux 安装FastCGI起来比较复杂。现在就在这里讲一下,在Unix/ Linux系统 下,Perl语言,Apache 服务器 环境下安装FastCGI。 Apache里FCGI的模块: 1、下载 http://www.fastcgi.com/dist/mod_fastcgi.tar.gz 2、解压apache安装文件。解压fastcgi安

  在Unix/Linux安装FastCGI起来比较复杂。现在就在这里讲一下,在Unix/Linux系统下,Perl语言,Apache服务器环境下安装FastCGI。
  
  Apache里FCGI的模块:
  1、下载http://www.fastcgi.com/dist/mod_fastcgi.tar.gz
  2、解压apache安装文件。解压fastcgi安装文件到apache下的/src/modules/fas tcgi目录
  3、设定Apache加入mod_fastcgi模块:
  ./configure --activate-module=src/modules/fastcgi/libfastcgi.a --enabl e-module=info --enable-shared=info
  4、编译及安装
  $ make
  $ make install
  5、查看编译出来的执行文件是否含有 mod_fastcgi 模块:
  $ apacherunpath/httpd -l
  Compiled-in modules:
  http_core.c
  ...
  mod_fastcgi.c
  ...
  6、加入使用 mod_fastcgi 的相关设定
  编辑httpd.conf加入AddHandler fastcgi-script .fcg .fpl这一行建立youwwwpath/fcgi-bin目录,设置/fcgi-bin/目录指到youwwwpath/fcgi-bin /在httpd.conf加入ScriptAlias /fcgi-bin/ /usr/local/www/fcgi-bin/
  7、检测语法错误
  $ /apachepath/apachectl configtest
  Syntax OK --系统显示
  8、重新激活阿帕契服务器,让新设定生效:
  $ /usr/local/apache/sbin/apachectl graceful
  /usr/local/apache/bin/apachectl graceful: httpd gracefully restarted --系统显示
  
  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++;
  }

原文转自:http://www.ltesting.net