看本文章者。请支持下我写的搜索 页面。

速谷歌  http://www.sugoogle.com 


[root@host src]# pwd

/usr/local/src

 

需要的包

httpd-2.2.6.tar.gz //apache服务器源文件包

mod_fastcgi-2.4.6.tar.gz  //apache的fastcgi模块源文件包

fcgi-devkit-2.4.0.tar  //fastcgi开发套件工具包

 

步骤

1.安装apache服务器

[root@host src]# tar zxvf httpd-2.2.6.tar.gz

[root@host src]# cd httpd-2.2.6

[root@host httpd-2.2.6]# ./configure --prefix=/usr/local/apache2.2.6

......(configure过程,略)

[root@host httpd-2.2.6]# make

......(make过程,略)

[root@host httpd-2.2.6]# make install

......(makeinstall过程,略)

如果在make过程中出现

......

include/apr.h:392:2: #error no decision has been made on APR_PATH_MAX for your platform

......

先备份apr.h,然后在apr.h的

#if defined(PATH_MAX)

#define APR_PATH_MAX PATH_MAX

之前加上

#if !defined(PATH_MAX)

#define PATH_MAX 4096

#endif

(Just check your PATH_MAX in limits.h to see if it's actually 4096)

[root@host httpd-2.2.6]# pwd

/usr/local/src/httpd-2.2.6

apache服务器被安装到了/usr/local/apache2.2.6。

[root@host httpd-2.2.6]# cd /usr/local/apache2.2.6/

启动apache服务器

[root@host apache2.2.6]# bin/apachectl start

[root@host apache2.2.6]# 

在浏览器地址栏输入http://localhost/

出现apache默认页面。

 

*安装cgi模块:(不知道此步是不是必须的)

看看/usr/local/apache2.2.6/modules下有没有mod_cgi.so模块,没有的话,我们来装下

[root@host apache2.2.6]# cd bin

[root@host bin]# pwd

/usr/local/apache2.2.6/bin

[root@host bin]# ./apxs -c -i /usr/local/src/httpd-2.2.6/modules/generators/mod_cgi.c 

(备注:./apxs -c -i /apache源文件路径/modules/generators/mod_cgi.c )

 

2.安装fastcgi模块

[root@host src]# tar zxvf mod_fastcgi-2.4.6.tar.gz

[root@host src]# cd mod_fastcgi-2.4.6

[root@host mod_fastcgi-2.4.6]# cp Makefile.AP2 Makefile

[root@host mod_fastcgi-2.4.6]# 

修改Makefile中的几个目录 

top_dir 需要指定,用apache安装的路径,我们当前的是/usr/local/apache2.2.6 

APXS 与 APACHECTL使用绝对路径 

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

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

[root@host mod_fastcgi-2.4.6]# make

......(make过程,略)

[root@host mod_fastcgi-2.4.6]# make install

......(makeinstall过程,略)

完成之后/usr/local/apache2.2.6/modules下应该有mod_fastcgi.so

 

3.修改apache配置文件/usr/local/apache2.2.6/confhttpd.conf

在相应的地方增加

LoadModule fastcgi_module modules/mod_fastcgi.so 

 

AddHandler cgi-script .cgi .pl # 传统的CGI处理扩展名 

AddHandler fastcgi-script .fcgi .fpl # FastCGI处理的扩展名 

 

重启apache服务器

[root@host apache2.2.6]# bin/apachectl restart

[root@host apache2.2.6]# 

 

此时cgi程序和fastcgi程序应该可以跑起来了

apache安装目录下有一个cgi-bin目录,里面test-cgi是一个cgi测试程序,可以在浏览器里测试一下

http://localhost/cgi-bin/test-cgi

如果有fastcgi程序,也可以测试一下。

如果想自己编写fastcgi程序,还要装fastCGI开发工具包。

 

4.安装fastCGI开发工具包

[root@host src]# tar xvf fcgi-devkit-2.4.0.tar

[root@host src]# cd fcgi-devkit-2.4.0

[root@host fcgi-devkit-2.4.0]# ./configure

......(configure过程,略)

[root@host fcgi-devkit-2.4.0]# make

......(make过程,略)

将 C 的头文件 (header file) 及函数库 (library) 安装至系统:

[root@host fcgi-devkit-2.4.0]# cp -rp include /usr/local/include/fastcgi

[root@host fcgi-devkit-2.4.0]# cp libfcgi/.lib/libfcgi.a /usr/local/lib

注:我看网上的是cp libfcgi/libfcgi.a /usr/local/lib,但是我机器上的libfcgi.a在libfcgi的隐藏目录.lib下

 

5.测试fastcgi

factcgi开发工具包中有简单的程序示例,直接把它拷到apache安装目录下的cgi-bin里即可(因为我这里没有用虚拟主机)。

注意扩展名要能与apache配置文件里的能匹配上。

[root@host fcgi-devkit-2.4.0]# cp examples/echo /usr/local/apache2.2.6/cgi-bin/

我这个开发包里没有以.fcgi或类似命名的,把echo直接拷到cgi-bin下,然后在浏览器里测试

http://localhost/cgi-bin/echo

刷新的时候并没有出现《实战FastCGI》里所说的Request number会一直累加而Process ID的值都不会改变,

而是Request number值一直为1,Process ID总在变。典型的cgi方式。

把echo改名为echo.fcgi再试,http://localhost/cgi-bin/echo.fcgi即可。

 

6.自己的fastcgi程序

《实战FastCGI》里写的很详细,直接贴过来一部分。

在程序里加上

#include "fcgi_stdio.h"

 

如果把 fcgi_stdio.h 头文件放在 /usr/local/include/fastcgi 这个目录下的话,

为了在编译时引入fcgi_stdio.h 头文件,请加入 -I/usr/local/include/fastcgi 的参数。

cc -I/usr/local/include/fastcgi -c program.c

FastCGI 程序要链接到libfcgi.a库才可正确生成可执行文件,

如果libfcgi.a的位置在/usr/local/lib 目录下,在链接时要加入-L/usr/local/lib -lfcgi 的参数。

cc -o program.fcg program.o -L/usr/local/lib -lfcgi

 

===end===

===end===

参考:Apache下FastCGI开发 http://hi.baidu.com/coffeefoam/blog/item/1446493be749f3e814cecbb8.html

      实战FastCGI http://www.phpchina.com/download/handbook/linux-html/1272.html

 

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐