skip to Main Content

I’m trying to find where a reference to /var/www/html still exists in my Apache configuration. When I run apache2ctl -S it says Main DocumentRoot: "/var/www/html", but none of my virual hosts or my main Apache config file point to that directory.

I have tried searching all of the config files using grep -r "var/www/html" /etc/apache2/ but it returns nothing.

There is no <Directory> entry for that path in my /etc/apache2/apache2.conf file (there is one for /var/www, under which I store the virtual hosts).

This configuration quirk bothers my OCD, but I also frequently see these entries in my Apache error log:

[Fri Jun 28 18:19:53.424619 2019] [autoindex:error] [pid 22665] 
[client 209.222.82.167:47376] AH01276: Cannot serve directory
   /var/www/html/: No matching DirectoryIndex 
   (default.php,index.php,index.html,index.htm) found, and server-generated
   directory index forbidden by Options directive

How does Apache decide what the main documentroot is, and how can I change it?

EDIT:

For my sites-available/sites-enabled, I have four files, 000-default.conf, 000-default-le-ssl.conf, 000-www-default.conf, and 000-www-default-le-ssl.conf. The 000-default.conf is a redirect set by certbot to point to the https site and has no DocumentRoot directive. The 000-www-default.conf is identical to 000-default.conf but for the ServerName (one has www and the other doesn’t); the same pattern follows for000-www-default-le.conf and 000-default-le.conf.

Here is the output of some things I’ve tried:

3

Answers


  1. Chosen as BEST ANSWER

    As @Nic3500 pointed out, the /var/www/html is the default value for the main DocumentRoot. Changing virtual host configurations does not affect this. However, adding a DocumentRoot directive to apache.conf does change it as reflected in the output of apache2ctl -S.

    In other words, my main DocumentRoot was unconfigured and the default value was used until I explicitly defined it in a global configuration file.


  2. In Debian/Ubuntu, the default virtual host file: /etc/apache2/sites-available/000-default.conf has the DocumentRoot /var/www/html.

    I think the Main DocumentRoot reported by apache2ctl -S is same as the default DocumentRoot. The default DocumentRoot is either defined in /etc/apache2/apache2.conf or in /etc/apache2/sites-available/000-default.conf. This is described in How to Change Default Apache ‘DocumentRoot’ Directory in Linux. So to change the Main DocumentRoot, you will need to edit /etc/apache2/sites-available/000-default.conf.

    Login or Signup to reply.
  3. The DocumentRoot directive Apache’s documentation is clear about its default value:

    Default: DocumentRoot "/usr/local/apache/htdocs"

    and Default means the value given by Apache when no one is specified anywhere:

    If the directive has a default value (i.e., if you omit it from your
    configuration entirely, the Apache Web server will behave as though
    you set it to a particular value
    )

    And yes, I know /usr/local/apache/htdocs is different from your value /var/www/html but this is just a minor detail which depends on the linux distribution the Apache was built to.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search