1:安装完成后,先编辑D:\wamp\bin\apache\apache2.2.22\conf下的http.conf文件,去掉#Include 0conf/extra/httpd-vhosts.conf前面的#号!!
2:找到安装目录D:\wamp\bin\apache\apache2.2.22\conf\extra\httpd-vhosts.conf找到VirtualHost节点 加入下一段即可
<VirtualHost *:80>
ServerName www.test.com
ServerAlias www.test.com
DocumentRoot E:/test
<Directory "E:/test">
Options Indexes FollowSymLinks
AllowOverride all
Order Allow,Deny
Allow from all
</Directory>
</VirtualHost>
php5.5及以上版本
<VirtualHost *:80>
DocumentRoot "D:\www\laravel5.1\public"
ServerName selfstudy.com
<Directory "D:\www\laravel5.1">
Options Indexes FollowSymLinks
AllowOverride all
Require all granted
</Directory>
</VirtualHost>
3: 修改Hosts文件 C:\WINDOWS\system32\drivers\etc\Hosts
127.0.0.1 www.test.com
有些时候配置完了虚拟主机发现访问localhost不会出现wamp的默认界面了那时因为没有配置localhost,加入如下配置即可
<VirtualHost *:80>
ServerName localhost
ServerAlias localhost
DocumentRoot "F:\wamp\www"
<Directory "F:\wamp\www">
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
# localhost访问默认根目录
<VirtualHost *:80>
DocumentRoot "D:\wamp\www"
ServerName localhost
<Directory "D:\wamp\www">
Options Indexes FollowSymLinks
AllowOverride all
Require all granted
</Directory>
</VirtualHost>
4:重启apache
5:如果出现403错误或者权限问题,把httpd.conf文件中的deny from all修改为 allow from all
6:如何在本地配置让别人可以直接访问你本地的项目
① 通过局域网ip访问
<VirtualHost 192.168.0.144:80>
ServerName test.chinanet.com
DocumentRoot "E:\www\chinanet"
<Directory "E:\www">
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
②通过域名(本地虚拟域名)访问
<VirtualHost *:80>
ServerName army.com
DocumentRoot "E:\army"
<Directory "E:\army">
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
本地hosts配置 127.0.0.1 army.com
同一局域网内要访问你的机器的hosts配置 192.168.1.68(我机器的ip) army.com