- 安装
安装完成 Wampserver 3.0.6,修改 DocumentRoot。
- 修改 DocumentRoot
修改服务器根目录路径:/wampserver_intall_dir/to/bin/apache/.../conf/httpd.conf
搜索 “DocumentRoot”,将当前行与下一行的目录路径,都修改为指定的根目录路径。
重启,http://localhost 发现返回相应没有改变。
- 测试
用一个错误的路径“D:\htdocs\”测试,发现 Wampserver 重启后,出现服务状态不正常。这说明配置文件肯定是修改对了。
右键点击,使用 Wampserver 工具 "Check httpd.conf syntax",提示 DocumentRoot must be a directory。Windows 中,使用右斜线()表示路径,结尾处不能带有 \ 。如果使用左斜线(/),结尾处可带上左斜线(/),也可以不需要。
确认修改的配置文件是正确的,为什么不生效呢?检查发现,apache 指定了一个 virtualhost:
<VirtualHost *:80>
ServerName localhost
DocumentRoot D:/wamp/wamp64/www
<Directory "D:/wamp/wamp64/www/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
注释 httpd-vhosts.conf 文件中 vhost 配置,重启 Wampserver,刷新页面就正常了。
Conclude
httpd-vhosts.conf 文件中,为某个 ServerName 指定的 DocumentRoot 是获得最高优先级的,而不会使用 httpd.conf 中所指定的。去掉 VirtualHost 配置中的 DocumentRoot 与 Directory
DocumentRoot D:/wamp/wamp64/www
<Directory "D:/wamp/wamp64/www/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
请求 "http://localhost",发现 httpd.conf 中使用 DocumentRoot 的生效了。