3
<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?

5
  • SetEnv will set the web server environment and it can be uses further from any script/program that can access the environment.
    – silviud
    Commented Apr 29, 2011 at 1:36
  • Yes I know. As I pointed out it binds too late to be used consistently in all properties (especially DocumentRoot)
    – SpliFF
    Commented Apr 29, 2011 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
    Commented Apr 29, 2011 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
    Commented Apr 29, 2011 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
    Commented Apr 29, 2011 at 13:05

1 Answer 1

2

This has been asked before. The link is here:

Using variables in Apache config files to reduce duplication?

1
  • Close enough. Since the syntax varies radically from Define I'll just wait till I'm using Apache 2.4.
    – SpliFF
    Commented May 1, 2011 at 6:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .