【问题标题】:On AWS EC2 Linux RHEL all PHP files are executing, except for index.php在 AWS EC2 Linux RHEL 上,所有 PHP 文件都在执行,除了 index.php
【发布时间】:2016-10-14 15:57:43
【问题描述】:

我迷路了。

我已经设置了一个 AWC EC2 RHEL 服务器,并安装了 php 和 apache。除了 index.php 文件不会执行之外,一切似乎都正常。如果我直接调用它们,所有其他 *.php 文件都可以使用。

index.php 包含:

<?php echo "test"; ?>

/etc/httpd/conf/httpd.conf我有设置:

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

虽然如果我删除 index.php 仍然不起作用。

我在index.php 上拥有-rw-r--r-- ec2-user ec2-user 的权限

我不确定还有什么其他信息在这里有用,因为除了 index.php 之外的所有其他 php 文件都可以工作。 (例如:如果我调用/index.php 什么都不输出,如果我将index.php 移动到index2.php 并调用/index2.php 输出test

对于为什么会发生这种情况有什么想法吗?

编辑

我现在意识到在调用 index.php 文件检查访问日志时会出现 500 内部服务器错误。

"GET /index.php HTTP/1.1" 500

也许这将有助于指明正确的方向?我仍然不清楚如何解决这个问题。同样,将文件名更改为 index.php 以外的任何名称(例如:index2.php)将正确执行文件。

此外,启用错误报告后,我收到此错误:

PHP Warning: Unknown: failed to open stream: Permission denied in Unknown on line 0

PHP Fatal error: Unknown: Failed opening required '/var/www/html/index.php' (include_path='.:/usr/share/pear:/usr/share/php') in Unknown on line 0

我尝试将权限更改为各种变体,包括 777、755、655、644、664 等……甚至尝试将所有者更改为 apache。不走运。

【问题讨论】:

    标签: php linux amazon-web-services amazon-ec2 rhel


    【解决方案1】:

    尝试将 selinux 配置为许可或禁用模式。

    我遇到了同样的问题。我试图安装moodle但失败了。我得到了同样的错误。

    我将 selinux 配置为 permissive,看看这是否是根本原因,我确实能够安装。

    我的问题是我以普通用户的身份在他的主目录下打开了 moodle 存档 (moodle...tar.gz) 并将其移动到 apache 的 DocumentRoot。这导致 selinux 内容字段错误。

    我已启用 selinux 并直接在 DocumentRoot (/var/www/html) 下打开 tar.gz 存档。这为文件 (httpd_sys_content_t) 提供了正确的内容属性。我能够在启用 selinux 的情况下运行 moodle。

    莫什

    【讨论】:

      【解决方案2】:

      AWS EC2 RedHat Web 服务器内部链接不起作用。 解决方案

      # Possible values for the Options directive are "None", "All",
      # or any combination of:
      # Note that "MultiViews" must be named explicitly --- "Options All"
      # doesn't give it to you.
      #
      # The Options directive is both complicated and important.  Please see
      # http://httpd.apache.org/docs/2.4/mod/core.html#options
      # for more information.
      #
      Options Indexes FollowSymLinks
      
      #
      # AllowOverride controls what directives may be placed in .htaccess files.
      # It can be "All", "None", or any combination of the keywords:
      #   Options FileInfo AuthConfig Limit
      #
      AllowOverride none 
      

      新值应更改为 AllowOverride all

      【讨论】:

        【解决方案3】:

        需要将权限设置为由 Apache 用户读取。当前权限不允许它以 Apache 用户身份读取文件。

        此外,最好检查一下您在 Apache 日志中遇到的错误,如果我没记错的话,它应该是“403 Forbidden”。

        【讨论】:

        • 所有用户的权限都是'r',所以apache可以读取文件。我在 apache 日志中没有看到任何提示错误的内容。另外,正如我所提到的,我可以简单地更改 index.php 的文件名,它会正确执行该文件。
        • 我意识到我忽略了访问日志中的 500 错误,所以不知道该怎么做。只发生在 index.php 文件上。所有其他 php 文件都在同一个根目录中工作。
        猜你喜欢
        • 2019-11-18
        • 2018-08-20
        • 2015-05-10
        • 2020-04-20
        • 2019-09-30
        • 2018-04-03
        • 2019-04-29
        • 2016-03-11
        • 1970-01-01
        相关资源
        最近更新 更多