这是我用 C 编写的简单的 hello-world FastCGI 脚本。
#include "fcgi_stdio.h"
#include <stdlib.h>
void main(void)
{
int count = 0;
while(FCGI_Accept() >= 0)
printf("Content-type: text/html\r\n"
"\r\n"
"<title>FastCGI Hello!</title>"
"<h1>FastCGI Hello!</h1>"
"Request number %d running on host <i>%s</i>\n",
++count, getenv("SERVER_NAME"));
}
如果我使用静态链接编译它,它工作正常。
gcc -o "test.fcg" "test.c" /usr/local/lib/libfcgi.a
但是当使用动态链接时...
gcc -o "test.fcg" -lfcgi "test.c"
它在 Apache 的error_log
.
/var/www/fcgi-bin/test.fcg: error while loading shared libraries: libfcgi.so.0: cannot open shared object file: No such file or directory
[Thu Mar 05 14:04:22.707096 2015] [:warn] [pid 6544] FastCGI: (dynamic) server "/var/www/fcgi-bin/test.fcg" (pid 6967) terminated by calling exit with status '127'
[Thu Mar 05 14:04:22.707527 2015] [:warn] [pid 6544] FastCGI: (dynamic) server "/var/www/fcgi-bin/test.fcg" has failed to remain running for 30 seconds given 3 attempts, its restart interval has been backed off to 600 seconds
所以我告诉 Apache 和 mod_fastcgi 寻找它所在的文件,将LD_LIBRARY_PATH
变量设置在httpd.conf
...
SetEnv LD_LIBRARY_PATH /usr/local/lib
...和fastcgi.conf
。
FastCgiConfig -initial-env LD_LIBRARY_PATH=/usr/local/lib -idle-timeout 20 -maxClassProcesses 1
使用静态链接脚本会getenv("LD_LIBRARY_PATH")
返回/usr/local/lib
,但动态链接脚本仍然会为libfcgi.so.0
.
有什么想法可以完成这项工作吗?
提前致谢。