Score:0

Why is htdocs not displaying directories when a virtual host has an error?

ge flag
EpF

I just set up Apache v2.4, PHP and MySQL on new windows machine. I've made only a few changes to httpd.conf. I'm including httpd-vhosts.conf, which has 2 custom sites defined (I removed the default dummy sites from it), both of which are WordPress sites.

One of those WordPress sites has no database, and when I go to the htdocs root directory, I see a database connection error for that site. When I comment out the DocumentRoot line of the virtual host, the directory listing shows up again.

Here are all the Directory-related lines from httpd.conf (in order):

Define SRVROOT "C:/webserv/Apache24"

ServerRoot "${SRVROOT}"

<Directory />
    AllowOverride none
    Require all denied
</Directory>

DocumentRoot "${SRVROOT}/htdocs"
<Directory "${SRVROOT}/htdocs">
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

<Directory "${SRVROOT}/cgi-bin">
    AllowOverride None
    Options None
    Require all granted
</Directory>

And here's the virtual host that causes the issue:

<VirtualHost *:80>#gutenberg
    DocumentRoot "${SRVROOT}/htdocs/gutenberg"
    ServerName gutenberg.squarestarmedia.ie
    ErrorLog "logs/gutenberg.localhost-error.log"
</VirtualHost>

(Note that I'm using my hosts file to point to the ServerName).

I should mention that I'm symlinking the htdocs directory from a different drive, but I have a very similar setup on another windows machine that is not experiencing the same issue.

How can I fix it so that htdocs always shows the directory listing, even if a sub-directory/virtual host has an error?

Score:1
ge flag
EpF

It appears that by default the server serves the top-most site in the virtual hosts file when going to the localhost root. The solution was to include a virtual host for the root htdocs directory itself. httpd-vhosts.conf:

<VirtualHost *:80>#
    DocumentRoot "${SRVROOT}/htdocs"
    ServerName localhost
    ErrorLog "logs/localhost-error.log"
</VirtualHost>

With this at the bottom of my virtual hosts file, localhost returns a directory listing no matter what.

djdomi avatar
za flag
remember that you need to accept your answer. else i have to review this question until the end of any decade
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.