centos 默认情况下不加载index.php

hsgswve4  于 2022-11-08  发布在  PHP
关注(0)|答案(9)|浏览(232)

我刚刚安装了CentOS,Apache和PHP。当我访问我的网站http://example.com/myapp/时,它说“禁止”。默认情况下,它不加载index.php文件。
当我访问http://example.com/myapp/index.php时,它工作得很好。
有办法解决这个问题吗?

ttvkxqim

ttvkxqim1#

Apache需要配置为将index.php识别为索引文件。
最简单的方法是...
1.在Web根目录中创建一个.htaccess文件。
1.添加行...
目录索引. php
这里有一个关于这件事的资源...
http://www.twsc.biz/twsc_hosting_htaccess.php
编辑:我假设apache配置为允许.htaccess文件,如果不是,您必须修改apache的配置文件(httpd.conf)中的设置。

yduiuuwa

yduiuuwa2#

虽然将“DirectoryIndex.php”添加到.htaccess文件中可能有效,

注意事项:

通常,您永远不应该使用.htaccess文件
引用自http://httpd.apache.org/docs/1.3/howto/htaccess.html
虽然这指的是Apache的旧版本,但我相信这个原则仍然适用。
将以下内容添加到 httpd.conf(如果您可以访问它)被认为是更好的形式,可以减少服务器开销,并具有完全相同的效果:

<Directory /myapp>
DirectoryIndex index.php
</Directory>

编辑:在编辑时,v1.3文档已关闭。v2.4文档(编辑时的当前版本)具有类似的立场:
一般来说,应该尽量避免使用.htaccess文件。任何你想放在.htaccess文件中的配置,都可以放在你的主服务器配置文件的<Directory>部分中。

64jmpszr

64jmpszr3#

我猜目录索引被设置为index.html,或者其他变体,试试看:

DirectoryIndex index.html index.php

这仍然会使index.html优先于index.php(如果您需要创建维护页面,这很方便)

6rvt4ljy

6rvt4ljy4#

这可能对某些人有帮助。下面是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。

yiytaume

yiytaume5#

这篇文章可能是旧的,但我只是张贴它的情况下,它有助于其他一些人,我不会建议创建一个.htaccess文件在您的网站根目录和改变索引。我觉得这是更好的按照步骤
1.转到你的apache文件夹的conf文件夹,我的是
C:\Apache24\conf
1.打开名为
httpd.conf
1.转到部分

<IfModule dir_module>
   DirectoryIndex index.html 

 </IfModule>

1.将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*
我希望它能帮助一些人...快乐编码

wpcxdonn

wpcxdonn6#

请尝试使用以下内容创建.htaccess文件

DirectoryIndex index.php

编辑:实际上,是不是有一个'php-apache'包或什么东西,你应该安装与他们两个?

bn31dyow

bn31dyow7#

在阅读了所有这些并试图修复它之后,我在ubuntu论坛上找到了一个简单的解决方案(https://help.ubuntu.com/community/ApacheMySQLPHP)。问题出在libapache 2-mod-php5模块上。这就是为什么浏览器下载index.php文件而不是显示网页的原因。请执行以下操作。如果sudo a2 enmod php5返回模块不存在,则问题出在libapache 2-mod-php5上。请使用命令sudo apt-get --来清除删除模块。清除删除libapache 2-mod-php5然后重新安装sudo apt-get安装libapache 2-mod-php5

zsbz8rwp

zsbz8rwp8#

我也遇到过类似的问题,我的愚蠢之处在于无意中在web根文件夹中也有一个空的index.html文件,当我没有显式请求index.php时,Apache提供的是这个文件而不是index.php,因为DirectoryIndexmods-available/dir.conf中是如下配置的:

DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm

也就是说,在优先级列表中,“index.html”出现在“index.php”之前。从web根目录中删除index.html文件自然就解决了这个问题。

p4tfgftt

p4tfgftt9#

这一个工作起来像一个魅力!

第一个

<IfModule dir_module>
    DirectoryIndex index.html
     DirectoryIndex index.php
</IfModule>

"然后从"

<Files ".ht*">
    Require all denied
</Files>

<Files ".ht*">
    Require all granted
</Files>

相关问题