【问题标题】:index.php is not loading by default in apache2index.php 在 apache2 中默认不加载
【发布时间】: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.htmlindex.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。

标签: php apache .htaccess


【解决方案1】:

当您转到 http://localhost/ 尝试按 Ctrl + F5 时,这可能是您浏览器中的缓存问题

【讨论】:

  • 啊,做到了!钱币。谢谢!
  • 是的@FrostedCookies 但是你每次都必须这样做,包括其他访问你的网站的人,如果它上线的话。我不认为这是一个具体的解决方案。
  • 哈哈,这花了我一段时间。该死的缓存!
猜你喜欢
  • 2011-01-23
  • 1970-01-01
  • 2014-02-18
  • 1970-01-01
  • 1970-01-01
  • 2013-02-03
  • 1970-01-01
  • 1970-01-01
  • 2013-04-01
相关资源
最近更新 更多