0

Apache/Nginx "default" document root path is usally /var/www/html but theoretically this could change tomorrow.

Having a distro-default and communally-maintained environment variable for it (instead of creating one myself, lowercased of course so I won't clash with existing uppercase envars) would ease me much because then I wouldn't need to do:

cat <<-EOF >> "$HOME"/.profile
    export drt="/var/www/html"

    drt() {
        cd $drt/
    }
EOF

Does document root have an envar in any common distro? Especially Debian/Arch?

1
+50

Here's one idea, since I found no evidence of an environment variable -- just default configurations in the various distributions:

case $(lsb_release -i) in
  (*Debian) conf=/etc/apache2/sites-available/000-default.conf;;
  (*Arch)   conf=/etc/httpd/conf/httpd.conf;;
esac
awk '/^[^#]*DocumentRoot/ { print "export drt=\""$2"\"" ORS 
                                  "drt() {" ORS 
                                  "  cd \"$drt\"/" ORS 
                                  "}" }' "$conf" >> "$HOME"/.profile

Each distribution can decide what it wants for defaults, so even the above method requires knowing where the base HTTPD configuration files are.

0

In Debian there are a bunch of Apache environment variables, but none for the document root.

What /usr/sbin/apachectl does is:

  1. look for APACHE_CONFDIR and set it to default value /etc/apache2 if not set.

  2. look for APACHE_ENVVARS (the environment variable file) and set it to default value "$APACHE_CONFDIR/envvars" if not set. this file is then sourced.

  3. modify APACHE_ARGUMENTS to include the path to the config directory if it was overridden.

  4. set default path to the binary /usr/sbin/apache2

  5. set a few other variables...

The default environment variable file contains these variables:

root@x250:/# grep export /etc/apache2/envvars
export APACHE_RUN_USER=www-data
export APACHE_RUN_GROUP=www-data
export APACHE_PID_FILE=/var/run/apache2$SUFFIX/apache2.pid
export APACHE_RUN_DIR=/var/run/apache2$SUFFIX
export APACHE_LOCK_DIR=/var/lock/apache2$SUFFIX
export APACHE_LOG_DIR=/var/log/apache2$SUFFIX
export LANG=C
export LANG
#export APACHE_LYNX='www-browser -dump'
#export APACHE_ARGUMENTS=''
#export APACHE2_MAINTSCRIPT_DEBUG=1

So you could

  • add variable "MY_HACKED_APACHE_DOCUMENT_ROOT" to /etc/apache2/envvars and modify your *.conf files
  • or smuggle in your path through APACHE_ARGUMENTS and check it/set it in your modified *.conf with <IfDefine>
  • or change the config directory APACHE_CONFDIR to a different path
  • or include a config file for a <VirtualHost> with a different DocumentRoot
  • or symlink /var/www/html to a different directory
  • ...

There are so many options! And honestly, I don't really think the debian guys will change /var/www/html in the near future. Why would they?

But if they do, you will probably see something like

This is the default welcome page used to test the correct operation of the Apache2 server after installation on Debian systems. If you can read this page, it means that the Apache HTTP server installed at this site is working properly. You should replace this file (located at /xxx/yyy/html/index.html) before continuing to operate your HTTP server.

Sorry, I can't tell how it's done in nginx.

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.