4

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!!!!

1 Answer 1

0

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.

5
  • Dammit! I had tried mod_env, but hadn't used the ${} syntax. Knew it had to be simple- thanks Warner :)
    – VLostBoy
    Jul 20, 2010 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, 2010 at 12:20
  • Sorry. Could you revisit and amend your answer? It fails to expand, e.g., "DocumentRoot ${MyRootDir}/public_html". Jul 24, 2010 at 1:51
  • My mistake, please see my revision user48842.
    – Warner
    Jul 24, 2010 at 17:12
  • Your link for mod_env is wrong — it points to mod_macro. Try httpd.apache.org/docs/2.0/mod/mod_env.html Dec 2, 2010 at 23:18

You must log in to answer this question.

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