Making rApache load rJava

I'm not going to cover how to set these things up here, there is pretty good documentation around the web and on rApache's site. Instead, I'm going to talk about a hair pulling setback I encountered early on.

Suffice it to say, this had me really really stumped. Stumped enough to give up temporarily and settle with calling R code that needed rJava via a PHP-to-shell intermediary. Of course, that got confusing and unscalable quite quickly, forcing me to find a real solution.

So how do you do this in an Apache process? I know that using a SetEnv directive in httpd.conf is a dead end. Thankfully, folks at the Ubuntu forums found a way.

Solution

Here's my modification of the Ubuntu forum solution.

Step 1:
Add a file to:

/etc/ld.so.conf.d

called:

rApache_rJava.conf

with just a single line:

/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/lib/amd64/server/

which happens to be the direct parent path to libjvm.so on my server.

Step 2:
As root, run:

/sbin/ldconfig

Step 3:
Restart Apache

Wrap-up

After all this rigamarole
it appears that I can load packages that depend on rJava from within
rApache - i.e. lines like

library(rJava)

no longer complain and I'm not getting any more HTTP 500 errors as a result, which makes me happy for the moment. How long this happiness lasts depends. R scripts within rApache still don't see an LD_LIBRARY_PATH variable, but at least the parent Apache process knows where to find libjvm.so.