首页 > 解决方案 > Laravel 文档根目录被 HTTP 403 错误禁止

问题描述

我有 laravel 安装了 CentOS 7 服务器。PHP、MariaDB 和 HTTPD 已安装并运行。所有服务都已启动并正常工作。浏览文档根显示

Forbidden
You don't have permission to access / on this server.

这是我服务器的文档根目录

DocumentRoot "/var/www/html/api/public"

文档根配置

<Directory "/var/www/html">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # 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

    #
    # Controls who can get stuff from this server.
    #
    Require all granted
</Directory>

这是welcome.conf 文件(/etc/httpd/conf.d/welcome.conf)

# This configuration file enables the default "Welcome" page if there
# is no default index page present for the root URL.  To disable the
# Welcome page, comment out all the lines below.
#
# NOTE: if this file is removed, it will be restored on upgrades.
#
<LocationMatch "^/+$">
    Options -Indexes
    ErrorDocument 403 /.noindex.html
</LocationMatch>

<Directory /usr/share/httpd/noindex>
    AllowOverride None
    Require all granted
</Directory>

Alias /.noindex.html /usr/share/httpd/noindex/index.html
Alias /noindex/css/bootstrap.min.css /usr/share/httpd/noindex/css/bootstrap.min.css
Alias /noindex/css/open-sans.css /usr/share/httpd/noindex/css/open-sans.css
Alias /images/apache_pb.gif /usr/share/httpd/noindex/images/apache_pb.gif
Alias /images/poweredby.png /usr/share/httpd/noindex/images/poweredby.png

我能为这个问题做些什么?

标签: phplaravelapachecentos7http-status-code-403

解决方案


下面的服务器配置解决了我的问题。

授予文件夹权限并设置所有权

chown -R apache:apache /var/www/html/laravel
chmod -R 755 /var/www/html/laravel/storage

恢复安全

restorecon -R /var/www

禁用 SELinux

setenforce 0

推荐阅读