FastCGI script can't find libfcgi.so.0 in Apache 2.4.6 and mod_fastcgi

拥有回忆 提交于 2019-12-25 03:12:29

问题


This is my simple hello-world FastCGI script written in C.

#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"));
}

It works fine if I compiled it using static linking.

gcc -o "test.fcg" "test.c" /usr/local/lib/libfcgi.a

But when using dynamic linking...

gcc -o "test.fcg" -lfcgi "test.c"

It fails whith the following error in Apache's 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

So I'm telling Apache and mod_fastcgi to look for that file where it's located setting the LD_LIBRARY_PATH variable in httpd.conf...

SetEnv LD_LIBRARY_PATH /usr/local/lib

...and fastcgi.conf.

FastCgiConfig -initial-env LD_LIBRARY_PATH=/usr/local/lib -idle-timeout 20 -maxClassProcesses 1

Using a static-linked script, getenv("LD_LIBRARY_PATH") returns /usr/local/lib, but dynamic-linked scripts are still throwing not found errors for libfcgi.so.0.

Any ideas to make this work?

Thanks in advance.


回答1:


I had similar issue with nginx, I fixed it by using rpath option.

Not sure if it will help with Apache. Try building your binary like this:

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

Make sure the library file libfcgi.so.0 is present at /usr/local/lib.

If you don't have access to /usr/local/lib, then create the lib folder in your $HOME, and copy the library file there. And update the rpath to point to there. For example, if your $HOME is /home/xyz, then you would build like:

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

Sometimes I use this trick to load newer libraries than what is installed on the system.



来源:https://stackoverflow.com/questions/28883708/fastcgi-script-cant-find-libfcgi-so-0-in-apache-2-4-6-and-mod-fastcgi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!