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.
PATH="/sbin:/usr/sbin:/bin:/usr/bin"
export PATH
Now append whatever environment variables you want to set and accessed by apache.
VAR="/path/to/var"
export VAR
For example,
LD_LIBRARY_PATH=/usr/local/lib:/usr/local/cuda/lib
export LD_LIBRARY_PATH
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.
Aryashree Pritikrishna Said:
on August 5, 2009 at 1:14 pm
Its working, thanks a lot.
Cheers,
Arya
Mayank Juneja Said:
on August 5, 2009 at 5:45 pm
You’re Welcome !