【发布时间】:2017-10-25 11:55:15
【问题描述】:
我刚刚安装了 Ubuntu 17.04 并设置了带有 PHP7 的 LAMP 服务器和为 Apache2 启用的 PHP 模块。
当我转到http://localhost/ 时,它默认为/var/www/html 中存在的index.html,而不是那里的index.php。当我转到http://localhost/index.php 时,php 文件加载得很好,并且 php 脚本会执行。
在查看其他帖子 (index.php not loading by default) 时,我看到首选的解决方案是编辑 /etc/apache2/mods-enabled/dir.conf 文件以将 index.php 移动到 DirectoryIndex 条目中的 index.html 之前。
<IfModule mod_dir.c>
DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
</IfModule>
所以我这样做并将文件保存为 sudo,重新启动 apache 服务并尝试重新启动计算机,它仍然首先提供 index.html。任何想法?我应该改用 .htaccess 文件解决方案吗?谢谢!
【问题讨论】:
-
为什么你同时拥有
index.html和index.php文件?你不能只删除index.html,这会导致localhost默认加载index.php吗?此外,您需要为要加载的 每个 文件指定DirectoryIndex。见stackoverflow.com/a/26700170/2341603。实际上,如果您只是将 PHP 文件指定为目录索引,那么拥有.html文件并不重要,因为 Apache 无论如何都会加载 PHP 文件。 -
你可以尝试在你的 apache 的 https.conf 文件中添加 'AddType application/x-httpd-php .php .html'
-
嘿@ObsidianAge 感谢您的回复。我认为这是一个缓存问题,如下所述,因为现在它工作正常。 DirectoryIndex 行就像开箱即用的那样,并且提到了要加载的帮助区域。我可以想象完全删除它是一个问题的唯一原因是,如果我有多个目录,并且如果我在子目录中有一些普通的旧
index.html如果我完全消除它,它们不会默认加载吗? -
你应该改变你的标题;我可以看到,在标题中使用“y”而不是“t”来表示 “index.php not loading by default” 会阻止您使用它。一个更改为更具描述性的标题。你现在拥有的,对任何搜索都没有帮助;无论是 Stack 还是 Google
-
这是最有可能解决此问题的问答 stackoverflow.com/questions/13640109/… - 其中“防止浏览器缓存”会向您显示结果是 Google。