- 用文本编辑器打开 Apache24/conf/httpd.conf
- 找到 #Include conf/extra/httpd-vhosts.conf 所在行, 去掉注释 #
- 打开 Apache24/conf/extra/ httpd-vhosts.conf
- 编辑如下:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "C:/Code/phpcode"
ServerName www.phpindex.com
</VirtualHost>
1. 增加域名解析 DNS: hosts
打开 C:\Windows\System32\drivers\etc\hosts 追加:
# php 虚拟主机相关配置
127.0.0.1 www.phpindex.com
- 重启Apache
给当前站点设置访问权限
<Directory "C:/Code/phpcode">
Require all denied
Require all granted
</Directory>
# 全部拒绝 Require all denied
# 全部授权 Require all granted
重启Apache服务
## apache2.4时访问权限需要写成 Require all granted
## 用旧版写法 Allow from all 会无法启动apache服务
## 开始我用旧版写法, 无法启动apache服务. 我搜索, 关键字为 php8 Allow from all 才找到解决的方法