我剛剛安裝了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