1、Host文件是用于DNS解析,本地的host文件优于网络上的DNS解析。找到目录C:\Windows\System32\drivers\etc下的host文件,用记事本打开在后面添加一行 127.0.0.1 www.test.com。
2、找到Apache下的httpd.conf文件,把虚拟主机开启。(如我的在:C:\wamp64\bin\apache\apache2.4.23\conf下)。
3、在httpd.conf文件中找到 #Include conf/extra/httpd-vhosts.conf这句话,将前面的#号去掉。
4、找到Apach下的httpd-vhosts.conf 一般是在apach安装目录下的conf目录下(如:C:\wamp64\bin\apache\apache2.4.23\conf\extra)
5、在httpd-vhosts.conf文件里添加如下代码<VirtualHost *:80> #网站根目录 Document伊怕锱鳏Root "F:/test" #域名 ServerName www.test.com #这里配置欢迎首页面 DirectoryIndex index.html index.htm index.php <Directory /> Options FollowSymLinks #不允许别人修改我们的页面 AllowOverride None #设置访问权限 order allow,deny Allow from all </Directory> </VirtualHost>
6、重启服务器,在网站目录根目录下新建1个index.php文件(我的在F:/test里面)。在index.php里写一句echo "这是网站首页!",用于测试。
7、在浏览器输入自己设置的域名,出现如下说明设置成功。
8、如果出现如下情况(浏览器状态码为403),就是因为权限不足引起的,再次打开httpd.conf进行添加权限
9、找到下面的代码<Dire罕铞泱殳ctory /> AllowOverride none Requ足毂忍珩ire all denied</Directory>将它改为:<Directory /> AllowOverride none Require all granted</Directory>就可以了