要解决这个问题,你可以通过编辑Apache的配置文件来更改默认的索引文件。以下是一种可能的解决方法:
打开 Apache 的配置文件。在 Ubuntu 上,它位于 /etc/apache2/apache2.conf,而在 CentOS 上,它位于 /etc/httpd/conf/httpd.conf。
找到 DirectoryIndex 指令。它定义了 Apache 在没有明确指定索引文件时应该使用的默认文件。默认情况下,它通常设置为 "index.html index.php"。
将 "index.php" 移动到指令的开头,使其成为第一个索引文件。例如,将 "DirectoryIndex" 的值修改为 "index.php index.html"。
示例:
DirectoryIndex index.php index.html
保存并关闭配置文件。
重新启动 Apache 服务,以使更改生效。在 Ubuntu 上,可以使用以下命令来重新启动 Apache:
sudo service apache2 restart
在 CentOS 上,可以使用以下命令:
sudo systemctl restart httpd
现在,当你访问 Apache 服务器时,它应该默认显示 index.php 而不是默认的测试站点。