[英]index.php not loading by default
我剛剛安裝了 CentOS、Apache 和 PHP。 當我訪問我的網站http://example.com/myapp/時,它顯示“禁止”。 默認情況下,它不加載 index.php 文件。
當我訪問http://example.com/myapp/index.php時,它工作正常。
知道如何解決這個問題嗎?
Apache需要配置為將index.php識別為索引文件。
完成這個的最簡單方法..
在Web根目錄中創建.htaccess文件。
添加行...
DirectoryIndex index.php
這是關於此事的資源......
http://www.twsc.biz/twsc_hosting_htaccess.php
編輯:我假設apache配置為允許.htaccess文件。 如果不是,則必須修改apache配置文件(httpd.conf)中的設置
將“DirectoryIndex index.php”添加到.htaccess文件可能有效,
注意:
通常,您不應該使用.htaccess文件
這是引自http://httpd.apache.org/docs/1.3/howto/htaccess.html
雖然這是指舊版本的apache,但我相信這個原則仍然適用。
將以下內容添加到httpd.conf (如果您有權訪問它)被認為是更好的形式,導致更少的服務器開銷並具有完全相同的效果:
<Directory /myapp>
DirectoryIndex index.php
</Directory>
猜測我會說目錄索引設置為index.html,或者某些變體,請嘗試:
DirectoryIndex index.html index.php
這仍將使index.html優先於index.php(如果您需要拋出維護頁面,則會很方便)
這可能對某人有幫助。 這是httpd.conf的片段(Apache 2.2版windows)
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
DirectoryIndex index.html
DirectoryIndex index.php
</IfModule>
現在這將尋找index.html文件,如果沒有找到它將尋找index.php。
嘗試使用以下內容創建.htaccess文件
DirectoryIndex index.php
編輯:實際上,是不是有'php-apache'包或者你應該用它們安裝的東西?
我在直接管理托管網站上的網站遇到了同樣的問題。 我補充道
DirectoryIndex index.php
作為自定義httd擴展(將代碼添加到站點httpd
文件),該站點默認運行index.php
。
閱讀完所有內容並嘗試修復后,我在ubuntu論壇( https://help.ubuntu.com/community/ApacheMySQLPHP )上得到了一個簡單的解決方案。 問題在於libapache2-mod-php5模塊。 這就是瀏覽器下載index.php文件而不是顯示網頁的原因。 請執行下列操作。 如果sudo a2enmod php5返回模塊不存在那么問題是libapache2-mod-php5。 使用命令sudo刪除模塊apt-get --purge刪除libapache2-mod-php5然后再次安裝它sudo apt-get install libapache2-mod-php5
有關信息:在某些Apache2 conf中,您必須在mods_enabled / dir.conf中添加DirectoryIndex命令(它不在apache2.conf中)
我有類似的症狀。 在我的情況下,我的白痴無意中也在web根文件夾中有一個空的index.html文件。 當我沒有明確請求index.php時,Apache服務於此而不是index.php,因為在mods-available/dir.conf
DirectoryIndex
配置如下:
DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
也就是說,'index.html'出現在優先級列表中的'index.php'之前。 從Web根目錄中刪除index.html文件自然解決了問題。 D'哦!
Ubuntu 16.04.4 LTS和Apache / 2.4.18的分步和完整說明
“ sudo -s
”
“ cd /etc/apache2/mods-enabled
”
“ vi dir.conf
”並將index.php移動到DirectoryIndex之后,如下所示並保存文件然后重啟apache服務器。
DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
“ service apache2 restart
”
如果你沒有看到dir.conf那么你需要加載它(谷歌如何)
完成。
這篇文章可能很舊,但我只是發布它,它可以幫助其他人,我不建議在你的web根目錄中創建.htaccess文件並更改索引。 我覺得按照步驟更好
轉到我的apache文件夾的conf文件夾
C:\\Apache24\\conf
打開名為的文件
httpd.conf
轉到該部分
<IfModule dir_module> DirectoryIndex index.html </IfModule>
將index.php添加到它,如下所示
<IfModule dir_module> DirectoryIndex index.html index.php </IfModule>
這樣,它仍然選擇index.html和index.php作為默認索引,但優先考慮index.html,因為index.html位於* index.php之前。 我的意思是你在同一個目錄中有index.html和index.php,index.html將用作默認索引,除了你在index.hml之前編寫** index.php *
我希望它有助於某人......快樂的編碼
這個就像一個魅力!
第一
<IfModule dir_module>
DirectoryIndex index.html
DirectoryIndex index.php
</IfModule>
之后呢
<Files ".ht*">
Require all denied
</Files>
至
<Files ".ht*">
Require all granted
</Files>
同樣的問題對我來說。 我的解決方案是mod_dir沒有啟用,並且在我的VirtualHost文件中讀取指令時apache2沒有發出錯誤:
DirectoryIndex index.html
使用命令:
sudo a2enmod dir
sudo sudo service apache2 restart
修復了這個問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.