unix安裝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
[email protected] 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++;
}