搭建本地虛擬主機有利於對建站的加深了解,提高自身的認識層面,而搭建本地虛擬主機也是一件非常簡單的事情
一、修改Apache的配置文件 httpd.conf文件
ctrl+f查找到下面代碼
Include conf/extra/httpd-vhosts.conf
把前面的#去掉
二、修改虛擬主機的httpd-vhosts.conf配置文件
找到下面代碼
#<VirtualHost *:80> #聲明端口 # ServerAdmin webmaster@dummy-host2.example.com # DocumentRoot "/Apache24/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>
ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot "E:/phpStudy/WWW/test"
ServerName test.com
ErrorLog "logs/dummy-host2.example.com-error.log"
CustomLog "logs/dummy-host2.example.com-access.log" common
</VirtualHost>
三、重啟Apache服務器
四、域名解析 修改hosts文件(一般在 C:\Windows\System32\drivers\etc)
在最后添加上即可

