Forbidden 您无权访问此服务器。Centos 6 / Laravel 4

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21498904/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 02:43:51  来源:igfitidea点击:

Forbidden You don't have permission to access on this server. Centos 6 / Laravel 4

apachelaravellaravel-4httpd.confhttp-status-code-403

提问by Fabrizio Fenoglio

i got a problem after i finish to set up LAMP and installed my laravel 4 application. Everything seem went well, when i go on my ip address url, it show me the first page of my application correctly, but all the rest of the page throw me an 404 error The requested URL was not found on this server.

我完成设置 LAMP 并安装我的 Laravel 4 应用程序后遇到问题。一切似乎都很顺利,当我访问我的 ip 地址 url 时,它正确地显示了我的应用程序的第一页,但页面的所有其余部分都向我抛出 404 错误在此服务器上找不到请求的 URL。

So I added to my httpd.conf (under the virtual host of my project) - AllowOverride All Order allow,deny

所以我添加到我的 httpd.conf(在我的项目的虚拟主机下) - AllowOverride All Order allow,deny

<VirtualHost *:80>
        ServerName VPS-IP-ADDRESS
        DocumentRoot /var/www/html/nextmatch/public_html/public/

       <Directory /var/www/html/nextmatch/public_html/public/>
         AllowOverride all
         Order allow,deny
          <IfModule mod_rewrite.c>
          Options -MultiViews
          RewriteEngine On
          RewriteCond %{REQUEST_FILENAME} !-f
         RewriteRule ^ index.php [L]
       </IfModule>
</Directory>
</VirtualHost>

And now when i try to navigate instead the 404 error i got Forbidden You don't have permission to access this server. I set up with chmod 775 -R path/laravel/and the folder storage with 777 but still i got the same error any suggest please? I cannot figure out to this problem i'm getting crazy! Thank you for any help.

现在,当我尝试导航而不是 404 错误时,我收到了 Forbidden 您无权访问此服务器的权限。我chmod 775 -R path/laravel/用 777设置了文件夹存储,但我仍然遇到相同的错误,请问有什么建议吗?我无法弄清楚这个问题我快疯了!感谢您的任何帮助。

回答by Rijndael

The webserver starts as a daemon (service) under a particular user. That user is defined in httpd.conf. By default that user will be apache. Don't confuse the apache user with the httpd process. The latter is a webserver daemon and the former is the user under which it is going to run. If the folder you created belongs to root or a user other than the one defined in httpd.conf then apache won't be able to access it. The way to identify this problem is to go to the folder and do ls -l. If the user define in httpd.conf is apache then in order for it to access the folder, you should see:

网络服务器作为特定用户下的守护程序(服务)启动。该用户在 httpd.conf 中定义。默认情况下,该用户将是 apache。不要将 apache 用户与 httpd 进程混淆。后者是一个网络服务器守护进程,前者是它将运行的用户。如果您创建的文件夹属于 root 用户或 httpd.conf 中定义的用户以外的用户,那么 apache 将无法访问它。确定这个问题的方法是到文件夹下执行ls -l。如果 httpd.conf 中的用户定义是 apache 则为了它访问该文件夹,您应该看到:

drwxr-xr-x.  2 apache apache    4096 Jan  8  2013 public_folder

Note, it says 'apache apache', meaning it belongs to the apache user and group. If you created it via root then you will probably see:

请注意,它说的是“apache apache”,这意味着它属于 apache 用户和组。如果您通过 root 创建它,那么您可能会看到:

drwxr-xr-x.  2 root root    4096 Jan  8  2013 public_folder

The apache user cannot access the folder defined by root. To solve this problem run the command:

apache 用户无法访问 root 定义的文件夹。要解决此问题,请运行以下命令:

chown -R apache:apache myfolder

The -R option is recursive, so it will update ownership for ALL folders and files within that folder to the apache user.

-R 选项是递归的,因此它将将该文件夹中所有文件夹和文件的所有权更新给 apache 用户。

If your ownership if fine, then trying 'temporarily' turning off selinux. On centos you do:

如果您的所有权正常,则尝试“暂时”关闭 selinux。在 centos 上你做:

setenforce 0

Which will turn off selinux till the next restart. Ideally, you will want to leave selinux on for additional security and set a valid context for your apache files and folders.

这将关闭 selinux 直到下次重新启动。理想情况下,您将希望保留 selinux 以提高安全性,并为您的 apache 文件和文件夹设置有效的上下文。

If turning off selinux does work, then you probably have the wrong security context for your files and folders. run the following command to restore your security contexts:

如果关闭 selinux 确实有效,那么您的文件和文件夹可能有错误的安全上下文。运行以下命令以恢复您的安全上下文:

restorecon -R -v /var/www/

回答by iavery

If you're using CentOS it could be an issue with selinux. Check to see if selinux is enabled with 'sestatus'. If it is enabled, you can check to see if that is the issue (temporarily) using 'sudo setenforce 0'. If apache can serve the site, then you just need to change the context of the files recursively using 'sudo chcon -R -t httpd_sys_content_t' (you can check the existing context using 'ls -Z'.

如果您使用的是 CentOS,则可能是 selinux 的问题。检查是否使用“sestatus”启用了 selinux。如果它已启用,您可以使用“sudo setenforce 0”检查这是否是问题(暂时)。如果 apache 可以为站点提供服务,那么您只需要使用 'sudo chcon -R -t httpd_sys_content_t' 递归更改文件的上下文(您可以使用 'ls -Z' 检查现有上下文。

Selinux may not be the issue, but it's worth checking on.

Selinux 可能不是问题,但值得检查。

回答by Mahdi

try this inside the folder:

在文件夹中试试这个:

chcon -R -t httpd_sys_content_t *

回答by tummie

chcon -R -t httpd_sys_content_t *

did the trick for me.

帮我解决了这个问题。

回答by Douglas G. Allen

from php5.conf in /etc/apache2/mods-available

来自 /etc/apache2/mods-available 中的 php5.conf

# Running PHP scripts in user directories is disabled by default
# 
# To re-enable PHP in user directories comment the following lines
# (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
# prevents .htaccess files from disabling it.
#<IfModule mod_userdir.c>
#    <Directory /home/*/public_html>
#        php_admin_value engine Off
#    </Directory>
#</IfModule>