我刚刚安装了Ubuntu 17.04,并为PHP2启用了LAMP服务器并启用了Apache2的PHP模块。index.php在apache2中默认没有加载
当我转到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
文件中的DirectoryIndex项index.html
之前移动index.php
。
<IfModule mod_dir.c>
DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
</IfModule>
所以我做了这一点,将文件保存为须藤,重新启动Apache服务,以及尝试重新启动计算机,它仍然会先的index.html。任何想法?我应该使用.htaccess文件解决方案吗?谢谢!
为什么你同时拥有一个'index.html'和'index.php'文件?难道你不能只删除'index.html',这会导致localhost默认加载'index.php'?另外,您需要为每个要加载的**文件指定'DirectoryIndex'。请参阅https://stackoverflow.com/a/26700170/2341603。事实上,如果您只是将PHP文件指定为目录索引,那么使用'.html'文件无关紧要,因为Apache将无论如何加载PHP文件。 –
您可以尝试在您的apache中的https.conf文件中添加'AddType application/x-httpd-php .php .html' – manian
嗨@ObsidianAge感谢您的回复。我认为这是一个缓存问题,如下所述,因为现在它工作正常。 DirectoryIndex行就像开箱即用,并提供了一个帮助区域提到要加载。我能想象的唯一原因是完全删除它是一个问题,如果我有多个目录,并且如果我有一些在子目录中普通的旧'index.html'不会默认加载,如果我完全删除它? – FrostedCookies