Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

It's CentOS 5. I created /etc/profile.d/ file where I set and export JAVA_HOME. Everything works fine in terminal.

When I'm trying to get this environment variable from PHP under Apache I get the following, after using shell_exec("env"):


Not even a sign of JAVA_HOME. Where should I declare it to make visible for apache?

share|improve this question
up vote 4 down vote accepted

You can do this by exporting the variables in /etc/sysconfig/httpd and then using the PassEnv directive to make them available to Apache e.g.

In /etc/sysconfig/httpd

export JAVA_HOME=/path/to/java_home

In /etc/httpd/conf.d/envvars.conf (for example)


Then restart the httpd service.

share|improve this answer
Works perfectly, thanks! – yegor256 Dec 19 '10 at 11:32

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.