2016-02-26 225 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”并运行。