Welcome to WebmasterWorld Guest from 54.205.75.60

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)

5+ Year Member



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)

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



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)

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



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