Zhang Jiuan’ Notes

Apache FAST-CGI配置[linux系统管理]

转载:http://www.pub4.com/?post=45

以下操作均是基于Linux,Windows用户可以参考配置
**********************************************************************
需要的软件
Apache2.2.3 http://apache.justdn.org/httpd/httpd-2.2.3.tar.gz
FastCGI模块 http://www.fastcgi.com/dist/mod_fastcgi-2.4.2.tar.gz
Perl的FastCGI模块
http://search.cpan.org/CPAN/authors/id/S/SK/SKIMO/FCGI-0.67.tar.gz

***********************************************************************

步骤1:
安装apache,我们用最简单的方式来做,只装apache和必要的模块,cgi什么的,先不
管,让我们的apache先运行起来
程序代码

tar xzvf httpd-2.2.3.tar.gz
cd http-2.2.3
./configure –prefix=/usr/local/apache2.2.3
make
make install

这样,我们就将apache装在了/usr/local/apache2.2.3目录下,进入
/usr/local/apache2.2.3/bin目录,执行

./apachectl start

访问下http://localhost/看看是不是看到了 It Works!的页面,如果没有,那么我想
你需要告诉我你看到了什么,否则你就得去apache的站点来看看如何去配置了。

步骤2:
通过了步骤1,可以进行FastCGI的安装了
首先要说明的一下是,FastCGI目前只支持到2.0,如果你用2.2版本以上的apache的话
,需要先运行一下patch,可以从下面的地址下载
点击下载此文件

Patch下好了吗?我们先把mod_fastcgi-2.4.2.tar.gz解压缩
程序代码

tar xzvf mod_fastcgi-2.4.2.tar.gz

其实安装很容易,我们继续..
程序代码

cd mod_fastcgi-2.4.2
cp /soft/fcgi-patch . 将刚才下的patch拷贝至当前目录
patch -p1 < fcgi-patch
cp Makefile.AP2 Makefile

修改一下Makefile中的几个目录
top_dir 需要指定,用apache安装的路径,我们当前的是/usr/local/apache2.2.3
APXS 与 APACHECTL使用绝对路径
程序代码

APXS      = /usr/local/apache2.2.3/bin/apxs
APACHECTL = /usr/local/apache2.2.3/bin/apachectl

好了,准备工作都好了,安装只需几秒,呵呵
程序代码

make
make install

好了吗?有没有错, 如果有错的话, 请来告知

步骤3:
还没有完成FastCGI与Apache的安装呢,这步就是要配置我们的应用,来使用FastCGI。
在测试FastCGI之前,你先看下/usr/local/apache2.2.3/modules下有没有
mod_fastcgi.so模块,如果没有,我想可能是见鬼了,也请告知

先配下我们的/usr/local/apache2.2.3/conf/http.conf吧

# Virtual hosts
Include conf/extra/httpd-vhosts.conf # 放开注释
  
LoadModule fastcgi_module modules/mod_fastcgi.so
AddHandler cgi-script .cgi .pl # 传统的CGI处理扩展名
AddHandler fastcgi-script .fcgi .fpl # FastCGI处理的扩展名

好了,配置的够多的了,不过现在还得配置一个最重要的东西,
/usr/local/apache2.2.3/conf/extra/httpd-vhosts.conf

<VirtualHost *:80>
    <Directory “/data/www/opensource”>
        DirectoryIndex index.htm index.html
    </Directory>
        
    Alias /cgi-bin/ “/data/www/opensource/cgi-bin/”
     
    <Directory “/data/www/opensource/cgi-bin”
        AllowOverride None
        Options ExecCGI
        Allow from all
    </Directory>
    DocumentRoot /data/www/opensource
    ErrorLog /usr/local/apache2.2.3/logs/error_log
    ServerName localhost
    ServerAlias 127.0.0.1
</VirtualHost>

步骤3很长,但都是需要做的,看看普通的cgi有没有问题吧。对了,你可能还没有装
cgi模块吧,确认下,看看/usr/local/apache2.2.3/modules下有没有mod_cgi.so模块
,没有的话,我们来装下

cd /usr/local/apache2.2.3/bin
./apxs -c -i /apache源文件路径/modules/generators/mod_cgi.c

好了,应该有了,将/usr/local/apache2.2.3/cgi-bin下的两个文件copy到你的cgi目
录中,我这里的是/data/www/opensource/cgi-bin/ 访问下看看
http://localhost/cgi-bin/printenv.pl

成功了吗?如果没有,告诉我发生了什么

来写个FCGI程序吧

步骤4:
得先装下FCGI 对于perl的模块

tar xzvf FCGI-0.67.tar.gz
cd FCGI-0.67
perl Makefile.PL
make
make test
make install

好了,写个小东西测试下吧,你可以把下面的代码直接进行copy

#!/usr/bin/perl -w
use FCGI;

my $count = 0;
while (FCGI::accept() >= 0) {
    print “Content-Type:text/html\n\n”;
    print “Your are “;
    print $count++;
    print ” Guess.”;
}

记得文件保存为.fpl结尾哦,存至cgi-bin目录,访问下看看
http://localhost/cgi-bin/xxx.fpl
看到了吗?没有?那发生了什么,告诉我

If you enjoyed this post, make sure you subscribe to my RSS feed!

No Comments, Comment or Ping

Reply to “Apache FAST-CGI配置[linux系统管理]”

You must be logged in to post a comment.

返回顶部