Maison > Article > développement back-end > PHP Apache 配置虚拟主机
1.找到Apache的\conf目录下的httpd.conf文件,打开它,找到下面这两行:
# Virtual hosts#Include conf/extra/httpd-vhosts.conf
把他前边的#号去掉,修改后如下如下:# Virtual hosts
Include conf/extra/httpd-vhosts.conf意思是启用虚拟主机的设置文件httpd-vhosts.conf,虚拟主机的设置都在这个文件下设置,不用去改httpd.conf,这样比较清晰。
打开它的时候里面已经含有像下面这样的内容:
?虚拟主机配置开始DocumentRoot "E:/wamp/www/ecshop"//网站的根路径-虚拟主机的目录,即域名对应的根目录
ServerName "www.baidu.com"//虚拟主机域名-你想要的域名ServerAlias www.dummy-host.localhost
ErrorLog "logs/dummy-host.localhost-error.log"CustomLog "logs/dummy-host.localhost-access.log" common
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride AllOrder allow,deny
Allow from allDeny from all意思是拒绝所有访问对根目录的访问,别人是访问不了你的网站的,
所以要想其他用户可以访问到你的项目就得改成
Allow from all加上一句下面的话
127.0.0.1 www.baidu.com?这个是你的域名,你要设置多少个虚拟主机,就要加多少行这样的记录。<directory>Options Indexes FollowSymLinks Includes ExecCGIAllowOverride AllOrder allow,denyAllow from all</directory><virtualhost>ServerAdmin webmaster@dummy-host2.localhostDocumentRoot E:\wamp\www\ecshopServerName www.test.comErrorLog logs/dummy-host2.localhost-error_logCustomLog logs/dummy-host2.localhost-access_log common</virtualhost>