在Apache的2.4.6和的mod_fastcgi FastCGI的脚本不能找到libfcgi.s

2019-10-29 06:38发布

这是用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

任何想法,使这项工作?

提前致谢。

Answer 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

有时候,我用这种伎俩来加载新的库比什么是安装在系统上。



文章来源: FastCGI script can't find libfcgi.so.0 in Apache 2.4.6 and mod_fastcgi