- 进入到XAMPP的安装目录,然后进入到 apache\conf\extra\目录下,打开httpd-vhosts.conf 文件
-
我之前用了YII 框架,那么把YII 框架的入口文件所在的目录设置为virtual host,加入下面的代码:
<VirtualHost *:80>
DocumentRoot "C:/software/xampp/Yii/basic/web"
ServerName localhost/Yii
ErrorLog "C:/software/xampp/Yii/error.log"
CustomLog "C:/software/xampp/Yii/custom.log" common
</VirtualHost>
在这里,我把YII框架的web目录作为了请求的根目录,然后就是设置了两个log,可以记录代码运行过程中的一些log信息。
-
保存之后,重新启动Apache 服务器,发现之前的一些项目却没法访问了。。。。
-
最后猜测可能是因为我们修改配置文件其实是覆盖了之前的设置,所以把之前的设置也放到这里:
<VirtualHost *:80>
DocumentRoot "C:/software/xampp/htdocs/"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/software/xampp/Yii/basic/web"
ServerName yii.localhost
ErrorLog "C:/software/xampp/Yii/error.log"
CustomLog "C:/software/xampp/Yii/custom.log" common
</VirtualHost>
可以看到,这次加了htdocs目录作为vitrual host,作为localhost默认加载的目录。重启Apache后,点击admin按钮正常的进入管理页面。
-
接下来,需要做的是,修改hosts 文件,把yii .localhost 域名设置为127.0.0.1,就可以在浏览器中访问yii.localhost这个域名来访问我们的框架了。。。
-
XAMPP Apache 设置virtual host
最新推荐文章于 2025-03-03 18:02:39 发布