Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.
<VirtualHost *:80>
SetEnv SITENAME testing
ServerName www.test.com

# Location of files
DocumentRoot "/www/${SITENAME}/site"
Alias /data "/www/data/${SITENAME}"
Alias /base "/www/${SITENAME}/base/site"

# Logging
ErrorLog "/var/log/httpd/${SITENAME}-error.log"
CustomLog "/var/log/httpd/${SITENAME}-access.log" combined
</VirtualHost>
  • Starting apache2 ... Warning: DocumentRoot [/www/${SITENAME}/site] does not exist

A further reading of the documentation provides a hint that SetEnv may not bind early enough to be used in paths and the suggested alternative SetEnvIf is based on the request properties as well.

I've also seen examples using mod_vhost_alias however that does not seem to handle anything but the DocumentRoot and even then it's required to use components of the server name which is not what I want.

What I want is pure variable substitution available when the config is read and usable in any string (like a #DEFINE in C). My Apache version is 2.2. Can it be done?

UPDATE: I found a Define directive in the documentation but it doesn't work (looks like it's new to 2.3). I guess the question now is wether there's a module that backports this or equivalent functionality to 2.2?

share|improve this question
    
SetEnv will set the web server environment and it can be uses further from any script/program that can access the environment. –  silviud Apr 29 '11 at 1:36
    
Yes I know. As I pointed out it binds too late to be used consistently in all properties (especially DocumentRoot) –  SpliFF Apr 29 '11 at 1:42
    
An important question to ask: why do you want this type of setup? What's the end goal of your configuration? –  BMDan Apr 29 '11 at 2:16
    
It simply makes setting up vhosts easy. I can edit the value in one place rather than 10. It isn't life or death it's just 9 less things to do when I create a new site. I typically use a sed script to replace all instances but sometimes it matches things it shouldn't. –  SpliFF Apr 29 '11 at 2:40
    
I would do some tokens into the config, have a script parsing the file and replace it later into the script then generate a config file and start apache. –  silviud Apr 29 '11 at 13:05

1 Answer 1

up vote 1 down vote accepted

This has been asked before. The link is here:

Using variables in Apache config files to reduce duplication?

share|improve this answer
    
Close enough. Since the syntax varies radically from Define I'll just wait till I'm using Apache 2.4. –  SpliFF May 1 '11 at 6:23

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.