许可被拒绝写入到一个目录,而不是其他的 - 都具有相同的所有者/组/ 755 [英] Permission denied writing to one directory, but not the other -- both have same owner/group/755

查看:246
本文介绍了许可被拒绝写入到一个目录,而不是其他的 - 都具有相同的所有者/组/ 755的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是推动我疯了。运行的httpd作为用户的Apache。我在/ var / www / html等内两个目录 - 上传和照片。两者都有组:阿帕奇老板:阿帕奇。两者都是755上传从PHP写的 - 照片是不是

This is driving me insane. httpd runs as the user apache. I have two directories within /var/www/html -- uploads and photos. Both have group:owner of apache:apache. Both are 755. uploads is writable from php -- photos is not.

一些测试code:

var_dump(touch('/var/www/html/photos/_test.log'));
var_dump(touch('/var/www/html/uploads/_test.log'));
var_dump(touch('/var/www/html/uploadsasdf/_test.log'));

和结果:

Warning: touch(): Unable to create file /var/www/html/photos/_test.log because Permission denied in /var/www/html/test.php on line 2
bool(false) 
bool(true) 
Warning: touch(): Unable to create file /var/www/html/uploadsasdf/_test.log because Permission denied in /var/www/html/test.php on line 4
bool(false)

我已经证实通过外壳和GUI界面的权限。我chowned和chmoded一切又只是要确定。我已经改名为上传目录到别的东西,并更名照片上传,看看目录的名字是这里的关键,但事实并非如此。这是目录本身。重命名上传一个新的名字仍然有效,并把照片目录,现在被称为上传没有。

I've confirmed permissions through a shell and GUI interface. I've chowned and chmoded everything again just to be sure. I've renamed the uploads directory to something else and renamed photos to uploads to see if the name of the directory was the key here, but it wasn't. It's the directory itself. The renamed uploads still works with a new name, and the photos directory that is now called "uploads" does not.

值得注意的是,_test.log不会在测试前的文件夹存在,所以它不是这样的文件有坏的权限,或任何东西。

Of note, _test.log does not exist in the folders before testing, so it's not like that file has bad permissions or anything.

有趣的是,如果我创建一个新的目录,它CHOWN到Apache:Apache的,执行命令chmod 777,我不能写,所以更大的东西可能是错在这里;但问题是:为什么然后进行上传目录工作

Interestingly, if I create a new directory, chown it to apache:apache, chmod it to 777, I can't write to it, so something larger may be wrong here; but the question remains: why then does the uploads directory work?

有没有人见过这种行为?我失去了一些东西明显?

Has anyone seen this behavior before? Am I missing something obvious?

在此先感谢您的帮助!

编辑补充更多的信息:

exec('whoami') 

阿帕奇

var_dump(posix_getpwuid(fileowner('/var/www/html/')));
var_dump(posix_getpwuid(fileowner('/var/www/html/uploads/')));
var_dump(posix_getpwuid(fileowner('/var/www/html/photos/')));

所有的阿帕奇

所有具有相同的fileperms()值。 然而,is_writable()是全是假的,但上传。

All have the same fileperms() value. However, is_writable() is false on all but "uploads".

mkdir('var/www/html/test');

警告命令mkdir():权限被拒绝。

Warning: mkdir(): Permission denied

ls-alF

drwxr-xr-x.  2 apache apache 286720 Nov 22 15:17 photos/
drwxr-xr-x.  2 apache apache  81920 Nov 22 12:06 uploads/
drwxr-xr-x.  2 apache apache      6 Nov 22 10:31 uploadsasdf/

我呼吁clearstatcache()函数;我已经重新启动服务器。什么... ...上的地球?

I have called clearstatcache(); I have rebooted the server. What ... on ... Earth?

推荐答案

由于您使用的CentOS和你已经尝试过其他的一切,我的猜测是一些相关的SELinux。一位来自这个问题的答案可能是有帮助的<一个href=\"http://stackoverflow.com/questions/21498904/forbidden-you-dont-have-permission-to-access-on-this-server-centos-6-laravel\">Forbidden您没有权限访问此服务器上。 CentOS 6的/ Laravel 4

Since you are using CentOS and and you've tried everything else, my guess would be something related to SELinux. One of the answers from this question may be helpful Forbidden You don't have permission to access on this server. Centos 6 / Laravel 4

具体试试这个分析SELinux的权限(LS -LZ),并暂时禁用SELinux:

Specifically try this to analyze SELinux permissions (ls -lZ) and temporarily disable SELinux:

如果你使用CentOS的它可能是SELinux的一个问题。请检查是否SELinux的与sestatus启用。如果启用,您可以检查,看看是否是问题(暂时)使用sudo的setenforce 0。如果Apache可以为网站,那么你只需要改变文件的递归使用sudo的chcon这个-r -t httpd_sys_content_t'的背景下(您可以使用检查现有情境LS -Z'。

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'.

这篇关于许可被拒绝写入到一个目录,而不是其他的 - 都具有相同的所有者/组/ 755的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆