20090909 passing env variables to rhels system httpd - plembo/onemoretech GitHub Wiki

title: Passing env variables to RHEL's system httpd link: https://onemoretech.wordpress.com/2009/09/09/passing-env-variables-to-rhels-system-httpd/ author: lembobro description: post_id: 255 created: 2009/09/09 14:07:04 created_gmt: 2009/09/09 14:07:04 comment_status: open post_name: passing-env-variables-to-rhels-system-httpd status: publish post_type: post

Passing env variables to RHEL's system httpd

Lately, I’ve been running a lot of stuff on the system httpd (Apache 2) for Red Hat Enterprise Linux (RHEL) 5.3. Today one of my cgi scripts that uses DBD::Oracle barked that it couldn’t find the Oracle client libraries it was complied with.

This is a common problem with DBD::Oracle, which on Apache compiled from source is solved by simply adding the line:

LD_LIBRARY_PATH=/path/to/oracle/client/libraries

to the top of the apachectl init script.

Of course RHEL has its own init script, /etc/init.d/httpd, and that trick won’t work with it. Neither will trying to set it up in the running user’s environment, the httpd system user doesn’t have a shell.

Turns out there’s a better way (isn’t there always?).

The shipping system httpd for RHEL comes with mod_env.so already compiled in and enabled. This is a very good thing, because, as it turns out, that is exactly the module needed to solve this problem.

All you need to do to pass an environment variable to httpd on RHEL with mod_env.so is to add a line like:

SetEnv LD_LIBRARY_PATH /path/you/need

to /etc/httpd/conf/httpd.conf (the location for the main Apache config file in RHEL).

In my case I put the following line just under “AddHandler cgi-script .cgi”, since this environment variable was most closely associated with my cgi scripts:

SetEnv LD_LIBRARY_PATH /opt/oracle/instantclient_11_1

Note that there’s no equals sign between the variable name and the path being set. The module will supply that. All you need to do is separate the variable and its value with whitespace.

After you’ve made this modification to httpd, restart Apache (/etc/init.d/httpd restart) and the runtime environment will now have the required path.

Copyright 2004-2019 Phil Lembo