Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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,

Steve

share|improve this question
    
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

2 Answers 2

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

TEXTDOMAIN=initscripts

. /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).

share|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
    
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

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

share|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

Your Answer

 
discard

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.