phpEnv默认首页由Apache的DirectoryIndex指令决定,需修改phpEnv\Apache\conf\httpd.conf中DirectoryIndex行(如DirectoryIndex home.php index.php index.html),并重启Apache服务生效。

phpEnv 的默认首页由 Apache 的 DirectoryIndex 决定
phpEnv 是基于 Apache + PHP 的 Windows 本地环境套件,它不自己定义首页逻辑,而是完全依赖 Apache 的 DirectoryIndex 指令。你放一个 home.php 在根目录却打不开,不是 PHP 问题,是 Apache 根本没轮到它——因为默认顺序是 index.html index.htm index.php,home.php 不在列表里。
修改 phpEnv 的 DirectoryIndex 配置文件位置
phpEnv 的 Apache 配置通常集中放在:phpEnv\Apache\conf\httpd.conf 或 phpEnv\Apache\conf\extra\httpd-default.conf。打开后搜索 DirectoryIndex,你会看到类似这一行:
DirectoryIndex index.html index.htm index.php
把它改成你想要的顺序,例如:
DirectoryIndex home.php index.php index.html
- 多个文件名之间必须用空格分隔,不能用逗号、换行或中文顿号
- 顺序越靠前,优先级越高;只要该文件存在且可读,就立刻返回,不再往后查
- 改完必须重启 phpEnv 的 Apache 服务(点托盘图标 → Restart Apache),否则配置不生效
- Linux 下区分大小写,Windows 一般不区分,但建议统一用小写命名,避免部署到生产环境出错
.htaccess 能否在 phpEnv 中覆盖 DirectoryIndex
可以,但需确认两点:AllowOverride All 已启用,且 .htaccess 放在网站根目录(比如 phpEnv\www\)。
立即学习“PHP免费学习笔记(深入)”;
在根目录新建或编辑 .htaccess,写入:
DirectoryIndex home.php index.php
注意:
- 这个设置会完全替代全局
DirectoryIndex,不是“追加”也不是“合并” - 如果子目录有自己独立的
.htaccess,则以子目录的为准 - phpEnv 默认开启
AllowOverride,但如果改过主配置,可能被关掉;可检查httpd.conf中对应<directory></directory>块内是否有AllowOverride All
为什么改了还是 403 或 404
常见真实原因不是配置错,而是这几个硬性条件没满足:
-
home.php文件确实存在于根目录,且文件名拼写完全一致(Home.php≠home.php) - 文件权限正常:Windows 下一般无权限问题,但若从压缩包解压或 Git clone 过来,偶尔会带只读属性,右键属性 → 取消“只读”
- 没启用目录浏览(
Options -Indexes是默认的),所以当所有DirectoryIndex文件都不存在时,Apache 直接返回 403(禁止列出目录内容),而不是 404 - 浏览器缓存了旧响应,尤其是 403;可尝试
curl -I http://localhost/看原始状态码,绕过缓存干扰
最易被忽略的是:phpEnv 启动后,它加载的是自身打包的 Apache 配置快照,有时修改了 httpd.conf 却忘了重启服务,或者改错了文件路径——它可能同时存在多个 httpd.conf 副本,务必确认你编辑的是实际被加载的那个。



















