最近用到了wamp环境,想创建一个虚拟主机,可是忘记了,于是百度了一下,把它写下来:
环境wampserver 2.4
找到安装目录,进入apache安装目录:找到conf 下的 httpd.conf
默认是 C:wampinapacheApache2.2.21conf 下的httpd.conf
找到这么一句
# Virtual hosts #Include conf/extra/httpd-vhosts.conf
改为
# Virtual hosts Include conf/extra/httpd-vhosts.conf
意思是开始虚拟主机配置,在conf/extra/httpd-vhosts.conf 下配置
模式的配置地址 C:wampinapacheApache2.2.21confextra httpd-vhosts.conf
找到和下面一样的代码,原本是不带#号的:
#<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>
上面的是我注释的,你也可以删除,然后改为
<VirtualHost *:80>
DocumentRoot "D:/www"
ServerName baidu.com
<Directory "D:/www">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
详细说明:
<VirtualHost *:80>
DocumentRoot "虚拟主机目录,项目路径"
ServerName 虚拟主机名字,也就是在本地访问的网址
<Directory "D:/www"> 对所给予的目录设置权限
Options Indexes FollowSymLinks
AllowOverride None // 在 AllowOverride 设置为 None 时, .htaccess 文件将被完全忽略
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
在你的目录下面放一个php文件,检测是否成功,我们普遍在里面写一句phpinfo,
以上是我用wamp配置的过程,最后可以成功访问php文件
新版apache 语法
<VirtualHost *:80>
ServerAdmin lenwang@tencent.com
ServerName sg.automall.qq.com
ServerAlias sg.automall.qq.com
DocumentRoot D:/svn/sg/trunk
<LocationMatch "/data/.*.php$">
Order Deny,Allow
Deny from All
</LocationMatch>
<Directory />
# Options -Indexes FollowSymLinks
Require all granted
AllowOverride All
</Directory>
# ErrorLog logs/newprj.qq.com-error_log
SetEnv MOD_ENV DEVELOPMENT
RewriteEngine on
RewriteCond %{REQUEST_URI} !^.*(.css|.js|.gif|.png|.jpg|.jpeg|.ico|.woff|.svg|.eot)$
RewriteRule .* /index.php
</VirtualHost>