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:
apache2ctl -V
: https://pastebin.com/R4ykihLvapache2ctl -S
: https://pastebin.com/JaEGQLgS$ sudo grep -r "/var/www/html" /
(partial, I stopped it after almost 5 hours): https://pastebin.com/9iJyAH9J
3
Answers
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 toapache.conf
does change it as reflected in the output ofapache2ctl -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.
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.
The DocumentRoot directive Apache’s documentation is clear about its default value:
and Default means the value given by Apache when no one is specified anywhere:
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.