LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (http://www.linuxquestions.org/questions/linux-networking-3/)
-   -   apache: Is apache config accepting shell env vars ? (http://www.linuxquestions.org/questions/linux-networking-3/apache-is-apache-config-accepting-shell-env-vars-751072/)

breeze99 08-29-2009 09:01 AM

apache: Is apache config accepting shell env vars ?
 
Linux x86_64 GNU/Linux , Server version: Apache/2.2.8 (Linux/SUSE)

Is there a method to pass to apache config, shell env var in place of hardcoded value ?

For examp I want apache reffer to config file defined by env var $PATH_TO_MY_LOCAL_CONFIG:
#######################################################################
Code:


tcsh> setenv PATH_TO_MY_LOCAL_CONFIG /mydir/my_ver_0.1/httpd.conf.local
tcsh> vim /etc/apache2/httpd.conf

PassEnv PATH_TO_MY_LOCAL_CONFIG
Include $PATH_TO_MY_LOCAL_CONFIG
:wq

tcsh> apache2ctl -k start
httpd2: Syntax error on line 214 of /etc/apache2/httpd.conf: Could not open configuration file /srv/www/$PATH_TO_MY_LOCAL_CONFIG: No such file or directory
tcsh>

#####################################################################

tnx.

bathory 08-29-2009 05:08 PM

Apache has its own env. variables, but they cannot do what you want. Also you can use shell env. variables, but only for CGIs and SSIs
In your case, can use your env. variables in a script or CLI. For example (in bash):
Code:

export PATH_TO_MY_LOCAL_CONFIG=/mydir/my_ver_0.1/httpd.conf.local
httpd -k start -c "Include PATH_TO_MY_LOCAL_CONFIG"

Regards

breeze99 08-30-2009 04:28 PM

Thanks for replay,
Finally thats worked .. (believe or not :o) )
Just share w/u my exp..
I did 2 thinks :
##################################################
<CODE>
1. Added module that support envs:
Should exists: /usr/lib64/apache2-prefork/mod_env.so
vim /etc/sysconfig/apache2
APACHE_MODULES=".. .. .. env .. .."
:wq
vim /etc/apache2/sysconfig.d/loadmodule.conf
LoadModule env_module /usr/lib64/apache2-prefork/mod_env.so
:wq
2. Added directive and fixed syntax , env vars should be enclosed by curly brackets :
vim /etc/apache2/httpd.conf
PassEnv PATH_TO_MY_LOCAL_CONFIG <== (directive to provide env var)
Include ${PATH_TO_MY_LOCAL_CONFIG} <== (should be in curly brackets)
:wq
</CODE>
####################################################
Now after starting apache2ctl its loaded all setings that coming
from file refered by $PATH_TO_MY_LOCAL_CONFIG
Thats good feature, now I can conditionally define config by changing shell var without touching http.conf it self.

Thanks.
~


All times are GMT -5. The time now is 04:24 PM.