7

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

Steve Griff
  • 233
  • 1
  • 2
  • 5
  • 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](http://www.redhat.com/search?q=%2Fetc%2Fenvironment&site=redhat&btnG=Search&getfields=title&client=external&proxyreload=0&proxystylesheet=external&output=xml_no_dtd&sort=date%3AD%3AL%3Ad1&entqr=3&oe=UTF-8&ie=UTF-8&ud=1) and a search on RedHat's Kbase returns nothing. – Stefan Lasiewski Mar 17 '11 at 21:13

2 Answers2

11

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

alvosu
  • 8,357
  • 24
  • 22
5

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

symcbean
  • 19,931
  • 1
  • 29
  • 49
  • 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 09 '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