0

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?

1 Answer 1

1

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.

1
  • remember that you need to accept your answer. else i have to review this question until the end of any decade
    – djdomi
    Mar 12, 2022 at 16:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .