Is there a way to use the DocumentRoot as a variable in further sections of a site's config file in Apache?

Something as below:

DocumentRoot /var/www/myNiceRoot

<Directory $DocumentRoot/mySubDir> ... </>

1 Answer 1


You can define a variable and then use that

Define droot /var/www/html

and then use it later

DocumentRoot ${droot}/site1

and so on.

  • A nice solution indeed. My question was assuming adding a section to the file without changing anything else. This would still do, provided I create a site file from the very beginning with such variable in it.
    – a1an
    Jan 25, 2016 at 14:03
  • You can define them in different scopes - look at the docs.
    – user9517
    Jan 25, 2016 at 14:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.