Monday, July 6, 2009

Accessing Operating System Environment Variables in Apache (Fedora)

I was facing the problem of accessing the Operating System Environment Variables in Apache. After searching a lot, I got to know that there are environment variables in apache too. Although these variables are referred to as environment variables, they are not the same as the environment variables controlled by the underlying operating system. Instead, these variables are stored and manipulated in an internal Apache structure.

For setting the operating system environment variables to be used by apache, we will export these variables to the apache server when it starts. The procedure is as follows :

0. Switch to root.

1. Open /etc/init.d/httpd in vim

vim /etc/init.d/httpd

2. You will find following lines

# Source function library.
. /etc/rc.d/init.d/functions

Open /etc/rc.d/init.d/functions in vim

vim /etc/rc.d/init.d/functions

3. You will find following lines

# Set up a default search path.
export PATH

Now append whatever environment variables you want to set and accessed by apache.


export VAR

For example,


You could have added these lines anywhere in the file.

4. Save the file and restart the apache server.

/etc/init.d/httpd restart

Hope it helps. I will add the fix for Ubuntu soon.