最近在Apache2.4上实践使用c/c++编写高性能cgi程序,在apache上配置mod_fastcgi模式的时候按照步骤始终不能成功,一直卡在mod_fastcgi的make上。提示错误如下(错误内容有省略):
[code="plain"]
/usr/local/apache/build/libtool --silent --mode=compile gcc -std=gnu99 -g -O2 -pthread -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -D_LARGEFILE64_SOURCE -I/usr/local/apache/include -I. -I/root/httpd-2.4.3/srclib/apr/include -I/root/httpd-2.4.3/srclib/apr-util/include -prefer-pic -c mod_fastcgi.c && touch mod_fastcgi.slo
mod_fastcgi.c: In function 'send_to_pm':
mod_fastcgi.c:175: warning: initialization from incompatible pointer type
mod_fastcgi.c:175: warning: passing argument 5 of 'ap_log_error_' makes integer from pointer without a cast
/usr/local/apache/include/http_log.h:372: note: expected 'apr_status_t' but argument is of type 'struct server_rec *'
mod_fastcgi.c:236: warning: initialization from incompatible pointer type
mod_fastcgi.c:236: error: expected expression before ')' token
mod_fastcgi.c:236: warning: passing argument 5 of 'ap_log_error_' makes integer from pointer without a cast
/usr/local/apache/include/http_log.h:372: note: expected 'apr_status_t' but argument is of type 'struct server_rec *'
mod_fastcgi.c: In function 'init_module':
mod_fastcgi.c:297: warning: initialization from incompatible pointer type
mod_fastcgi.c:297: warning: passing argument 5 of 'ap_log_error_' makes integer from pointer without a cast
/usr/local/apache/include/http_log.h:372: note: expected 'apr_status_t' but argument is of type 'struct server_rec *'
mod_fastcgi.c:301: warning: initialization from incompatible pointer type
mod_fastcgi.c:301: warning: passing argument 5 of 'ap_log_error_' makes integer from pointer without a cast
/usr/local/apache/include/http_log.h:372: note: expected 'apr_status_t' but argument is of type 'struct server_rec *'
mod_fastcgi.c:329: warning: initialization from incompatible pointer type
mod_fastcgi.c:329: error: expected expression before ')' token
[/code]
于是搜寻各大网站终于在一个serverfault上找到有人提供的mod_fastcgi for apache2.4的解决方案
https://github.com/ByteInternet/libapache-mod-fastcgi
于是赶紧下载下来解压编译,依旧提示类似的编译错误,看了下安装手册才发现需要先大补丁才能编译。于是尝试使用作者提供的patch来给fastcgi官网提供的源码包打补丁:
(1)下载补丁文件
/upload/other/byte-compile-against-apache24.diff
(2) cd /root/mod_fastcgi-2.4.6 并上传本文中提供的diff patch文件到此目录
(3) 然后patch -p1 < byte-compile-against-apache24.diff 即可
(4)注意修改Makefile.AP2 为Makefile 同时修改里面的apache的路径(top_dir)为自己apache所部属的路径。
(5) 最后make && make install 编译mod_fastcgi,然后在apache的conf文件中加入module即可。
附编译fcgi遇到的问题:
如下错误:
[code="plain"]
g++ -DHAVE_CONFIG_H -I. -I. -I.. -I../include -g -O2 -c fcgio.cpp -MT fcgio.lo -MD -MP -MF .deps/fcgio.TPlo -fPIC -DPIC -o .libs/fcgio.lo
fcgio.cpp: In destructor 'virtual fcgi_streambuf::~fcgi_streambuf()':
fcgio.cpp:50: error: 'EOF' was not declared in this scope
fcgio.cpp: In member function 'virtual int fcgi_streambuf::overflow(int)':
fcgio.cpp:70: error: 'EOF' was not declared in this scope
fcgio.cpp:75: error: 'EOF' was not declared in this scope
fcgio.cpp: In member function 'virtual int fcgi_streambuf::sync()':
fcgio.cpp:86: error: 'EOF' was not declared in this scope
fcgio.cpp:87: error: 'EOF' was not declared in this scope
fcgio.cpp: In member function 'virtual int fcgi_streambuf::underflow()':
fcgio.cpp:113: error: 'EOF' was not declared in this scope
make[2]: *** [fcgio.lo] Error 1
make[2]: Leaving directory `/root/fcgi-2.4.1-SNAP-0311112127/libfcgi'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/root/fcgi-2.4.1-SNAP-0311112127'
make: *** [all] Error 2
[/code]
我的gcc版本是4.4,搜寻网上的解决方案是在fcgio.h上加载cstdio头部
引文链接:https://bugs.gentoo.org/show_bug.cgi?id=256654
在编写fcgi程序的时候我们时常需要reload cgi才能重新看到新编译的程序效果,其实我们可以在apache的配置文件中加上如下配置来提供自动的reload策略,而不需要人工的重启来重新加载新程序。
[code="plain"]
<IfModule mod_fastcgi.c>
FastCgiconfig -autoUpdate
</IfModule>
[/code]