Ben Crowell asked:
Apache2 recently changed the default root directory from /var/www to /var/www/html, which breaks the scripts I distribute for installing some software I wrote. Is there a reliable way of detecting from a script which it is? I would prefer a reasonably portable solution, say one that would run on Linux, BSD, and MacOS.
I guess I could check for the existence of the html subdirectory, but that doesn’t seem very bulletproof.
I also thought of this:
source /etc/apache2/envvars ; apache2 -S
This generates output that actually seems wrong:
Main DocumentRoot: "/var/www"
In fact, the root directory on this machine is /var/www/html.
If your script is called via CGI or FastCGI, it should find the document root in the
DOCUMENT_ROOT environment variable.
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.