1、编译和安装:
1)、下载:从http://www.fastcgi.com/drupal/下载fcgi.tar.gz;
2)、解压:tar xzvf fcgi.tar.gz
3)、配置:
./configure --prefix=/home/pub/johnny/network/install-fcgi --host=mips-linux-gnu --disable-FEATURE --without-PACKAGE "CC=mips-linux-gnu-gcc -EL" "CFLAGS=-EL" "LDFLAGS=-EL" "CXX=mips-linux-gnu-g++ -EL" "CXXFLAGS=-EL"
4)、make;在make时出现以下错误:
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
解决办法:
在/include/fcgio.h文件中加上 #include <cstdio>,然后再编译安装就通过了。
是由于GCC版本问题导致。
5)、make install;
在/home/pub/johnny/network/install-fcgi有 bin/、include/、lib/三个文件夹;
copy到开发板上;
2、测试:
1)、代码:
http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs_ModFastCGI
#include <stdlib.h> #include <string.h> #include <syslog.h> #include <alloca.h> #include <fcgiapp.h> #define LISTENSOCK_FILENO 0 #define LISTENSOCK_FLAGS 0 int main(int argc, char** argv) { openlog("testfastcgi", LOG_CONS|LOG_NDELAY, LOG_USER); int err = FCGX_Init(); /* call before Accept in multithreaded apps */ if(err){ syslog (LOG_INFO, "FCGX_Init failed: %d", err); return 1; } FCGX_Request cgi; err = FCGX_InitRequest(&cgi, LISTENSOCK_FILENO, LISTENSOCK_FLAGS); if(err){ syslog(LOG_INFO, "FCGX_InitRequest failed: %d", err); return 2; } while(1){ err = FCGX_Accept_r(&cgi); syslog(LOG_INFO, "Receive Request!"); if(err){ syslog(LOG_INFO, "FCGX_Accept_r stopped: %d", err); break; } char** envp; int size = 200; for (envp = cgi.envp; *envp; ++envp) size += strlen(*envp) + 11; char* result = (char*) alloca(size); strcpy(result, "Status: 200 OK\r\nContent-Type: text/html\r\n\r\n"); strcat(result, "<html><head><title>testcgi</title></head><body><ul>\r\n"); for (envp = cgi.envp; *envp; ++envp) { strcat(result, "<li>"); strcat(result, *envp); strcat(result, "</li>\r\n"); } strcat(result, "</ul></body></html>\r\n"); FCGX_PutStr(result, strlen(result), cgi.out); } return 0; }
编译:
mips-linux-gnu-gcc -EL -I/home/pub/johnny/network/install-fcgi/include -L/home/pub/johnny/network/install-fcgi/lib -lfcgi testfastcgi.c -o test.fastcgi
2)、copy到开发板tmp/bin/下;
3)、修改conf.d/fastcgi.conf:
fastcgi.server = ( "/test.php" => (( "socket" => "/tmp/lighttpd.player.server.socket", "bin-path" => "/tmp/bin/test.fastcgi", "max-procs" => 1, # "host" => "127.0.0.1", # "port" => 8081, "check-local" => "disable", )) )
4)、在PC上运行http://192.168.9.*/test.php,在网页上显示fastcgi的运行环境,而且每刷新一次网页,打印一次“Receive Request!”;