2016-02-26 217 views
0

我只安裝在Ubuntu一個Apache 2.4 & PHP 5.5.6 12.04阿帕奇2.4錯誤404

當我打電話的web瀏覽器的頁面 - >mysite.com/index.php,網頁通常與作品展示,但如果我叫頁面mysite.com(沒有/index.php)我得到錯誤404,Apache不會自動加載index.php。

我需要在瀏覽器的導航欄中寫這個(該網站也有一個index.html)。我的虛擬主機mysite.conf是:

<VirtualHost *:80> 
ServerAdmin [email protected] 
DocumentRoot /home/alexbk/webs/mysite 
ErrorLog /home/alexbk/webs/mysite/error.log 
CustomLog /home/alexbk/webs/mysite/access.log combined 

<Directory /home/alexbk/webs/mysite> 
Options Indexes FollowSymLinks MultiViews 
Require all granted 
AllowOverride All 
</Directory> 
</VirtualHost> 

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet --> 

該文件夾沒有和htacess文件。我嘗試更改apache2.conf,但沒有運氣。

感謝您的幫助

+0

看到這篇文章:http://stackoverflow.com/questions/2384423/index-php-not-loading-by-default –

回答

1

以下應爲你工作:

<VirtualHost *:80> 
    ServerAdmin [email protected] 
    DocumentRoot /home/alexbk/webs/mysite 
    ErrorLog /home/alexbk/webs/mysite/error.log 
    CustomLog /home/alexbk/webs/mysite/access.log combined 

    <Directory /home/alexbk/webs/mysite> 
     Options Indexes FollowSymLinks MultiViews 
     Require all granted 
     AllowOverride All 
     DirectoryIndex index.php 
    </Directory> 
</VirtualHost> 

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet --> 

編輯:

如果不工作,去編輯/ etc/apache2的/ MODS -enabled/dir.conf並將其更改爲:

<IfModule mod_dir.c> 
    DirectoryIndex index.html index.cgi index.pl index.xhtml index.htm 
</IfModule> 

<IfModule mod_dir.c> 
    DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm 
</IfModule> 

作爲一個側面說明,如果你能不精啓用MODS的文件夾內的文件dir.conf那麼你需要運行下面的命令:

sudo a2enmod dir 
+0

如果我添加行目錄索引,apache崩潰,以下錯誤:AH00526:語法/etc/apache2/sites-enabled/mysite.conf的第10行錯誤: 命令'DirectoryIndex'無效,可能是拼寫錯誤或未包含在服務器配置中的模塊定義 –

+0

好的,從dentalvox.org.conf中刪除該行然後。而是去編輯/etc/apache2/mods-enabled/dir.conf。在那裏你應該有一行說:DirectoryIndex index.html index.cgi index.pl index.xhtml index.htm改變說的DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm –

+0

我忘了說,如果你找不到dir.conf文件,那麼你需要運行「sudo a2enmod dir」 –

0

感謝加油,爲你的幫助,我的問題是沒有一個dir.load文件在mods-available文件夾中,那麼命令「sudo a2enmod dir」不起作用,我需要創建一個dir.load文件(用下面的代碼行: LoadModule dir_module /usr/lib/apache2/modules/mod_dir.so);確保.so文件存在並保存到mods-available文件夾中,然後我可以運行「a2enmod dir」並運行。