apache版本以2.4为例
1、修改httpd.conf
把下面第二行的#去掉,启动虚拟主机配置
# virtual hosts # include conf/extra/httpd-vhosts.conf
2、配置httpd-vhost.conf
这里使用了8081端口,配置了两个虚拟主机,documentroot不能含有中文目录
<virtualhost *:8081>
servername localhost
directoryindex index.php
documentroot "d:\work\php\apache24\htdocs"
<directory "d:\work\php\apache24\htdocs">
options indexes followsymlinks
allowoverride none
order allow,deny
allow from all
</directory>
</virtualhost>
<virtualhost *:8081>
servername www.aa.com
directoryindex index.php
documentroot "e:\php\phpprojectbase"
<directory "e:\php\phpprojectbase">
options indexes followsymlinks
allowoverride none
order allow,deny
allow from all
</directory>
</virtualhost>
3、etc/hosts配置
127.0.0.1 localhost127.0.0.1 www.aa.com
4、重启apache服务
如果此时虚拟主机仍不能访问,配置httpd.conf中以下项
<directory />
allowoverride none #require all denied</directory>
以上就是关于php之apache配置虚拟主机的详细内容。