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.

say for example I have a configuration something like this

<VirtualHost 127.0.0.1:80>

    DocumentRoot "path/to/docroot"

    <Directory /path/to/docroot/private>
        #blah
    </Directory>

    <Directory /path/to/docroot>
        #blah
    </Directory>

    <Directory /path/to/docroot/anotherdir>
        #blah
    </Directory>
</VirtualHost>

I'm constantly qualifying paths using /path/to/docroot. I want to be able to declare the path value of /path/to/docroot at the head of the file just once, and find a way to declare subsequent directory directives relative to that path.

Is there anything like this I can do? (Pretend Var is a madeup directive that lets you declare a path value then refer to it later)

<VirtualHost 127.0.0.1:80>
    Var DocRoot "path/to/docroot"
    DocumentRoot DocRoot

    <Directory DocRoot/Private>
      #blah
    </Directory>

    <Directory DocRoot>
      #blah
    </Directory>

    <Directory DocRoot/anotherdir>
      #blah
    </Directory>
</VirtualHost>

Is there anything like this I can use? Thanks!!!!

share|improve this question

1 Answer 1

up vote 0 down vote accepted

mod_env is used to set variables that can be passed to CGI and SSI pages. What you want to do does not necessarily have any native support that I am aware of.

One solution would be to use the third party module called mod_macro, which would allow a more dynamically generated httpd.conf but is not exactly what you are seeking.

If you have mod_perl installed, you can embed perl code within the httpd.conf using <perl> and </perl>, which would allow a more dynamic httpd.conf. mod_perl executes it on startup. If you are not already running mod_perl, the overhead introduced would not be worthwhile.

A third option would be to dynamically generate your configuration using a set of scripts, which would be outside of Apache all together. Perl would be a very useful language for this particular application.

share|improve this answer
    
Dammit! I had tried mod_env, but hadn't used the ${} syntax. Knew it had to be simple- thanks Warner :) –  VLostBoy Jul 20 '10 at 22:27
    
Sorry Warner- that doesn't work. Can you confirm that it works for you? I don\t believe its a configuration issue on myside- I have mod_env module loaded. Thanks again! –  VLostBoy Jul 21 '10 at 12:20
    
Sorry. Could you revisit and amend your answer? It fails to expand, e.g., "DocumentRoot ${MyRootDir}/public_html". –  Charles Merriam Jul 24 '10 at 1:51
    
My mistake, please see my revision user48842. –  Warner Jul 24 '10 at 17:12
    
Thanks for the advice and the correction Warner :) –  VLostBoy Jul 28 '10 at 10:07

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.