这是用C写的我简单的hello世界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
。
任何想法,使这项工作?
提前致谢。