FastCGI脚本在Apache 2.4.6和mod_fastcgi中找不到libfcgi.so.0

时间:2015-03-05 17:12:43

标签: c apache centos7 mod-fastcgi

这是我用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的{​​{1}}变量的文件......

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抛出未找到的错误。

任何使这项工作成功的想法?

提前致谢。

1 个答案:

答案 0 :(得分:1)

我和nginx有类似的问题,我使用rpath选项修复了它。

不确定它是否对Apache有帮助。尝试构建这样的二进制文件:

gcc test.c -Wl,-rpath /usr/local/lib -lfcgi -o test.fcg

确保库文件libfcgi.so.0出现在/usr/local/lib

如果您无权访问/usr/local/lib,请在lib中创建$HOME文件夹,然后将库文件复制到该文件夹​​中。并更新rpath以指向那里。例如,如果您的$HOME/home/xyz,那么您将构建如下:

gcc test.c -Wl,-rpath /home/xyz/lib -lfcgi -o test.fcg

有时我使用这个技巧来加载比系统上安装的库更新的库。