I am attempting to modify the DocumentRoot for a virtual host in Apache. The DocumentRoot setting for the virtual host is being ignored, and instead the overall DocumentRoot is being used.
In my case, instead of using /Applications/AMPPS/www/public as the root folder, Apache is using /Applications/AMPPS/www.
The relevant part of the httpd.conf file is given below. Does anyone see a problem?
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "/Applications/AMPPS/www"
...snip...
<VirtualHost 127.0.0.1:80>
<Directory "/Applications/AMPPS/www">
Options FollowSymLinks Indexes
AllowOverride All
Order deny,allow
allow from All
</Directory>
ServerName localhost
ServerAlias localhost 127.0.0.1
ScriptAlias /cgi-bin/ "/Applications/AMPPS/www/cgi-bin/"
DocumentRoot "/Applications/AMPPS/www/public"
ErrorLog "/Applications/AMPPS/apache/logs/error_log"
CustomLog "/Applications/AMPPS/apache/logs/access.log" combined
</VirtualHost>
It seems that the VirtualHost
is not being used, which would explain why the DocumentRoot
from the main server config is active. You perhaps need to add NameVirtualHost
before the VirtualHost
block. Like this:
NameVirtualHost 127.0.0.1
<VirtualHost 127.0.0.1:80>
...
Also remove the ServerAlias
directive completely as both entires you have in there are not doing anything. You don't need to duplicate localhost there because you have it as the ServerName and it doesn't accept IP addresses. An IP address will be served the first matching VirtualHost
that is assigned to it.
Ref: NameVirtualHost Directive
NameVirtualHost was dropped in Apache 2.4 so I'm assuming you are on an earlier release. From 2.4 on it works without it.