Welcome to WebmasterWorld Guest from 54.162.91.86

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Modify apache config files on start

apache config start

     
7:57 pm on Apr 23, 2014 (gmt 0)

Junior Member

5+ Year Member

joined:Apr 3, 2009
posts:57
votes: 0


In my test environments I'm using variables for the basic apache configs. In my init.d startup script I just export some variables like:
ENVT=test


Then in the apache config files I have values like:
ServerName www.${ENVT}.abc.com


This is working fine however I'm a bit stumped as to how I can have that variable removed when it comes to production where it should be just www.abc.com. Is there a way I can modify my startup script to run a sed command on the file to load into memory instead of actually modifying the copy on disk? The sed command below works; I just need to figure out if it's possible to have the apache config files modified before the binary reads them. Feels like something fairly simple I'm missing, but maybe not. Or maybe I'm just taking the wrong approach.


if [ ${ENVT} == prod ]; then
`/bin/sed -r 's/\.\$\{ENVT\}//g' /apps/httpd/conf.d/*.conf`
fi
9:21 pm on Apr 23, 2014 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:13674
votes: 439


ServerName www.${ENVT}.abc.com

The thought that jumped out at me was: Why not include a trailing or leading . in the variable value itself? Then if the variable is empty, it's as if the whole thing didn't exist.

Obviously this doesn't remove the variable. It just makes it irrelevant.

Obligatory disclaimer: I don't speak Apache, so I don't know whether this would make the server explode.
12:54 am on Apr 24, 2014 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:10846
votes: 61


I would set the environment variiable differently in production and test environments:
ENVT=test
vs
ENVT=www.test

then in the apache config files use:
ServerName ${ENVT}.example.com