最近用到了wamp环境,想创建一个虚拟主机,可是忘记了,于是百度了一下,把它写下来:
环境wampserver 2.4
找到安装目录,进入apache安装目录:找到conf 下的 httpd.conf
默认是 C:\wamp\bin\apache\Apache2.2.21\conf 下的httpd.conf
找到这么一句
1
2
|
# Virtual hosts
#Include conf/extra/httpd-vhosts.conf
|
改为
1
2
|
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
|
意思是开始虚拟主机配置,在conf/extra/httpd-vhosts.conf 下配置
模式的配置地址 C:\wamp\bin\apache\Apache2.2.21\conf\extra httpd-vhosts.conf
找到和下面一样的代码,原本是不带#号的:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
#<VirtualHost *:80>
# ServerAdmin webmaster@dummy-host.example.com
# DocumentRoot
"c:/Apache2/docs/dummy-host.example.com"
# ServerName dummy-host.example.com
# ServerAlias www.dummy-host.example.com
# ErrorLog
"logs/dummy-host.example.com-error.log"
# CustomLog
"logs/dummy-host.example.com-access.log"
common
#</VirtualHost>
#<VirtualHost *:80>
# ServerAdmin webmaster@dummy-host2.example.com
# DocumentRoot
"c:/Apache2/docs/dummy-host2.example.com"
# ServerName dummy-host2.example.com
# ErrorLog
"logs/dummy-host2.example.com-error.log"
# CustomLog
"logs/dummy-host2.example.com-access.log"
common
#</VirtualHost>
|
上面的是我注释的,你也可以删除,然后改为
1
2
3
4
5
6
7
8
9
10
11
12
|
<VirtualHost *:80>
DocumentRoot
"D:/www"
ServerName baidu.com
<Directory
"D:/www"
>
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
|
详细说明:
1
2
3
4
5
6
7
8
9
10
11
12
|
<VirtualHost *:80>
DocumentRoot
"虚拟主机目录,项目路径"
ServerName 虚拟主机名字,也就是在本地访问的网址
<Directory
"D:/www"
> 对所给予的目录设置权限
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
|
在你的目录下面放一个php文件,检测是否成功,我们普遍在里面写一句phpinfo,
以上是我用wamp配置的过程,最后可以成功访问php文件
修改C:/WINDOWS/system32/drivers/etc/host这个文件,用记事本打开,加上如下内容:
127.0.0.1 www. cms.com
好了,然后重启apache,在浏览器里面输入www.cms.com,看看访问到的内容是不是workplace这个目录呢。