Ubuntu + Rails + Passenger + OCI8 = Sad

Load­Er­ror (Oracle/OCI libraries could not be loaded: libclntsh.so.11.1: can­not open shared object file: No such file or direc­tory — /usr/local/lib/site_ruby/1.8/i486-linux/oci8lib.so)

Have you seen this error in your Rails appli­ca­tion? Do you hate it as much as I do? I’ve spent the past two days trou­bleshoot­ing this and I finally found a solu­tion. It’s ugly and hacky, but it appears to be working.

There are actu­ally quite a few posts out there regard­ing this error and they all get down to the root prob­lem: the LD_LIBRARY_PATH envi­ron­ment vari­able is not avail­able to the Apache user (www-data in this case). Most solu­tions I’ve found involve set­ting this vari­able in /etc/bash.bashrc or /etc/profile to make the vari­able avail­able to all users. This fixed part of the prob­lem for me, but it was still fail­ing when exe­cuted from Apache via Passenger.

The “solu­tion”

The hack­tas­tic solu­tion was to mod­ify the /etc/init.d/apache2 startup script and explic­itly set the LD_LIBRARY_PATH vari­able when Apache is started. Specif­i­cally, change

ENV="env -i LANG=C PATH=/usr/local/bin:/usr/bin:/bin"

to

ENV="env -i LANG=C PATH=/usr/local/bin:/usr/bin:/bin LD_LIBRARY_PATH=/opt/oracle/instantclient"

Note that this solu­tion assumes you’re using the Ora­cle Instant­Client; if you’re using the full Ora­cle client, you may try set­ting the ORACLE_HOME path instead of LD_LIBRARY_PATH.

I hope this helps somebody!

2 comments

  1. Great guy!
    I was like… 5 hours to make this work.. and now its work­ing!!
    Thanks a lot!

  2. Really help­ful.

Comment on this post

You may use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>