# Trouble setting LD\_LIBRARY\_PATH for FastCGI script

**URL:** <https://www.ruby-forum.com/t/trouble-setting-ld-library-path-for-fastcgi-script/99180>\
**Category:** Ruby\
**Created:** [July 20, 2006, 8:56pm UTC](https://www.ruby-forum.com/t/trouble-setting-ld-library-path-for-fastcgi-script/99180 "2006-07-20T20:56:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_Gansen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/b77776/32.png) [@Chris\_Gansen](https://www.ruby-forum.com/u/Chris_Gansen)\
**Post date:** [July 20, 2006, 8:56pm UTC](https://www.ruby-forum.com/t/trouble-setting-ld-library-path-for-fastcgi-script/99180/1 "2006-07-20T20:56:59Z")

</div>

Hello -

I’m trying to exec a ruby script via FastCGI (on Apache 2.0), and cannot  
properly set the env. variable LD\_LIBRARY\_PATH at run time.

I’ve tried adding:

SetEnv LD\_LIBRARY\_PATH /path/to/lib

in a .htaccess file, but to no avail. Perl, however, happily recognizes  
it.  
Setting ENV[‘LD\_LIBRARY\_PATH’] does not take effect either.

In the error\_log, I see:

[Thu Jul 20 11:32:33 2006] [warn] FastCGI: (dynamic) server  
“/web/server\_root/fcgi-bin/index.fcgi” restarted (pid 11242)  
/path/to/ruby\_bin/lib/ruby/site\_ruby/1.8/i686-linux/fcgi.so:  
libfcgi.so.0:  
cannot open shared object file: No such file or directory -  
/path/to/ruby\_bin/lib/ruby/site\_ruby/1.8/i686-linux/fcgi.so (LoadError)  
from  
/path/to/ruby\_bin/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:21:in  
`require’  
from /path/to/index.fcgi:23

Strangely, when I execute the fcgi script from the command line, as:

$ LD\_LIBRARY\_PATH=/path/to/lib ./index/fcgi

I receive:

./index.fcgi:25: undefined method `each\_cgi’ for FCGI:Class  
(NoMethodError)

Which is particularly vexing. This configuration works on another  
machine,  
where the libraries are not in ‘special’ places.

Any advice on how to get Ruby to find the correct library?

-c-

---

<div class="post-metadata">

**Author:** ![Chris\_Gansen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/b77776/32.png) [@Chris\_Gansen](https://www.ruby-forum.com/u/Chris_Gansen)\
**Post date:** [July 20, 2006, 9:52pm UTC](https://www.ruby-forum.com/t/trouble-setting-ld-library-path-for-fastcgi-script/99180/2 "2006-07-20T21:52:27Z")

</div>

Chris Gansen writes:

> Hello -
> 
> I’m trying to exec a ruby script via FastCGI (on Apache 2.0), and  
> cannot  
> properly set the env. variable LD\_LIBRARY\_PATH at run time.
> 
> I’ve tried adding:
> 
> SetEnv LD\_LIBRARY\_PATH /path/to/lib
> 
> in a .htaccess file, but to no avail. Perl, however, happily  
> recognizes it.  
> Setting ENV[‘LD\_LIBRARY\_PATH’] does not take effect either.

I set this in Apache’s httpd.conf file, in the   
declaration. You will also want to make sure you declare all the  
libraries needed. If you just declare “/path/to/lib”, the libraries  
wouldn’t necessarily know where to find libraries in /usr/lib, for  
example. Here is the line I used (on my Solaris system):  
SetEnv LD\_LIBRARY\_PATH  
/usr/lib:/usr/local/lib:/usr/openwin/lib:/usr/local/pgsql/lib

(Probably don’t really need the /usr/openwin/lib, but…)  
You would have to restart Apache, but I expect you would have to do  
that anyways if one could set the same thing in the .htaccess.

> In the error\_log, I see:
> 
> [Thu Jul 20 11:32:33 2006] [warn] FastCGI: (dynamic) server  
> “/web/server\_root/fcgi-bin/index.fcgi” restarted (pid 11242)  
> /path/to/ruby\_bin/lib/ruby/site\_ruby/1.8/i686-linux/fcgi.so:  
> libfcgi.so.0:  
> cannot open shared object file: No such file or directory -  
> /path/to/ruby\_bin/lib/ruby/site\_ruby/1.8/i686-linux/fcgi.so  
> (LoadError)  
> from

/path/to/ruby\_bin/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:21:in

> `require’  
> from /path/to/index.fcgi:23
> 
> Strangely, when I execute the fcgi script from the command line, as:
> 
> $ LD\_LIBRARY\_PATH=/path/to/lib ./index/fcgi
> 
> I receive:
> 
> ./index.fcgi:25: undefined method `each\_cgi’ for FCGI:Class  
> (NoMethodError)
> 
> Which is particularly vexing. This configuration works on another  
> machine,  
> where the libraries are not in ‘special’ places.
> 
> Any advice on how to get Ruby to find the correct library?
> 
> -c-

Are you sure you’ve installed FastCGI on this system? Based on what I  
see in the log file:

1. The server cannot find libfcgi.so.0, which is installed with  
FastCGI. Make sure the file is present.
2. You’ve probably installed ruby-fcgi since it knew about  
FCGI:Class, but the fcgi.so file would require the libfcgi.so library.  
Did you copy the ruby libraries over, but not the system libraries?

Coey

–  
Coey M.  
Senior Test Engineer  
(651) 628-2831  
removed\_email\_address@domain.invalid

Secure Computing(R)  
Securing Connections between People, Applications, and Networks™  
[http://www.securecomputing.com](http://www.securecomputing.com)  
NASDAQ: SCUR

\*\*\* The information contained in this email message may be privileged,  
confidential and protected from disclosure. If you are not the intended  
recipient, any review, dissemination, distribution or copying is  
strictly prohibited. If you have received this email message in error,  
please notify the sender by reply email and delete the message and any  
attachments. \*\*\*

---

<div class="post-metadata">

**Author:** ![Chris\_Gansen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/b77776/32.png) [@Chris\_Gansen](https://www.ruby-forum.com/u/Chris_Gansen)\
**Post date:** [July 20, 2006, 10:30pm UTC](https://www.ruby-forum.com/t/trouble-setting-ld-library-path-for-fastcgi-script/99180/3 "2006-07-20T22:30:46Z")

</div>

On 7/20/06, Coey M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I set this in Apache’s httpd.conf file, in the   
> declaration. You will also want to make sure you declare all the  
> libraries needed. If you just declare “/path/to/lib”, the libraries  
> wouldn’t necessarily know where to find libraries in /usr/lib, for  
> example. Here is the line I used (on my Solaris system):  
> SetEnv LD\_LIBRARY\_PATH  
> /usr/lib:/usr/local/lib:/usr/openwin/lib:/usr/local/pgsql/lib

Unfortunately, I’m in a very restrictive environment, for multiple  
reasons.  
There are no vhosts, and custom configuration directives must either be  
in  
.htaccess or a stanza. It’s my understanding that .htaccess  
would have the same effect as setting it in , though.  
Furthermore, when I run a Perl fcgi script to dump $ENV, I see the  
SetEnv  
value:

LD\_LIBRARY\_PATH =\> /path/to/fcgi\_bin/lib

> see in the log file:
> 
> 1. The server cannot find libfcgi.so.0, which is installed with  
> FastCGI. Make sure the file is present.
> 2. You’ve probably installed ruby-fcgi since it knew about  
> FCGI:Class, but the fcgi.so file would require the libfcgi.so library.  
> Did you copy the ruby libraries over, but not the system libraries?

FastCGI is installed, but not in the typical fashion. I have the  
FastCGI  
libraries, libfcgi.so.0, etc installed in a user directory, which is why  
I’m  
trying to set LD\_LIBRARY\_PATH, so Ruby will look for the libraries in  
the  
right place. And no, I cannot install into the system library  
(/usr/lib).

Thanks for the help,  
–chris
