We have CentOS with Apache running on it. Basically, I have a few variables in /etc/environment and they're passed through to our Apache configs using PassEnv. The issue is that because Apache is before /etc/environment the variables are not found.

Is there a similar kind of /etc/environment file that I can add my global environmental variables into that is executed before apache (httpd) or do I have to start editing runlevels?

Kind regards,


  • I'm trying to figure this out as well. I'm not convinced that CentOS uses /etc/environment at all. A search on redhat.com and a search on RedHat's Kbase returns nothing. – Stefan Lasiewski Mar 17 '11 at 21:13

Use "/etc/sysconfig/httpd" to set Apache environment.

| improve this answer | |
  • I would like the environmental variables to be accessible from the command line too, as there are some PHP scripts that we use that need those variables. – Steve Griff Feb 9 '11 at 10:59
  • For those using Debian/Ubuntu, the file to edit is /etc/apache2/envvars – Hamish Downer Oct 16 '15 at 10:23
  • this does not work on aws ec2 – shorif2000 Jul 20 at 20:53

If these are variables which apply to each and every user on the system, then they should be added in /etc/enviornment - but IIRC this file is not explicitly parsed by the init scripts.

So you'd need to add a line in /etc/rc.d/init.d/functions, e.g.

# -*-Shell-script-*-
# functions     This file contains functions to be used by most or all
#               shell scripts in the /etc/init.d directory.
# amended to set env vars


. /etc/environment

However if you only want these vars to be available to the webserver, then they should be declared in /etc/sysconfig/httpd, e.g.

# Configuration file for the httpd service.

export MYSQL_USER = mydbuser

(might work without the explicit export).

| improve this answer | |
  • Looks like the best solution so far... although I'm surprised that a file such as /etc/environment or something similar is not parsed early during the init process. Am I approaching this problem from the wrong angle? – Steve Griff Feb 9 '11 at 12:28
  • 1
    Trying /etc/sysconfig/httpd myself, it didn't seem to make the vars available to a bash script running as apache until I added export like you showed here. – Doug Kavendek Aug 24 '12 at 15:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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