[英]Centos 7 / Apache / PHP - mkdir(): Permission denied
Before you yell DUPLICATE! 在你大喊大叫之前! and banish me into the abyss, hear me out. 把我赶进深渊,听我说。 :) :)
I've been developing an intranet site for the company I work with, and originally I was developing it directly from my workstation running Windows 7 / IIS . 我一直在为我合作的公司开发一个Intranet站点,最初我是从运行Windows 7 / IIS的工作站直接开发它。 As I've neared completion of the site/applications, I was given a Centos 7 box that's running Apache , so I've begun the process of migrating it over to that system. 当我接近完成站点/应用程序时,我得到了一个运行Apache的Centos 7盒子,所以我开始将它迁移到该系统。 I've sorted out most of the minor issues, and got the site running now. 我已经整理了大部分小问题,现在让网站运行了。 However, there is a portion of the site that interacts with our database and creates a log directory/file based upon the person that's logged in. This portion utilizes the mkdir() function, but I'm getting permission issues with it. 但是,该站点的一部分与我们的数据库交互,并根据登录的人创建一个日志目录/文件。这部分使用mkdir()函数,但我收到了权限问题。
mkdir(): Permission denied
Here is what I've already done: 这是我已经做过的事情:
So whether I use chmod or chown to change the permissions for the folders being accessed, I'm getting the same type of error. 因此,无论我使用chmod还是chown来更改正在访问的文件夹的权限,我都会遇到相同类型的错误。 To be on the safe side, I checked the PHP user also, and it's using the apache user as well. 为了安全起见,我也检查了PHP用户,并且它也使用了apache用户。
If anyone may have additional insight as to why it isn't working, even with the permissions changed, then please enlighten me. 如果有人可能有额外的洞察力,为什么它不工作,即使权限已更改,那么请赐教。 If I happened to miss the one article that explained this particular situation, then yell duplicate and banish me to the abyss. 如果我碰巧错过了一篇解释这种特殊情况的文章,那么大喊大叫并将我驱逐到深渊。 lol :) 大声笑 :)
EDIT Okay, so upon further testing, I've discovered 2 issues that seem to be causing this overall issue. 编辑好的,经过进一步的测试,我发现了两个似乎导致这个整体问题的问题。
Just to note, I've attempted to set the recursive value to true on mkdir in PHP, but that's when I get the permission issues originally noted. 请注意,我试图在PHP中的mkdir上将递归值设置为true,但是当我得到最初提到的权限问题时。 When recursive/mode is removed, it doesn't get the permission issue, but it isn't able to create nested directories. 删除递归/模式时,它不会获得权限问题,但无法创建嵌套目录。
EDIT2 EDIT2
To test my theories, I removed the nesting and tried to make mkdir create just 1 directory, and it's generating the same errors as before. 为了测试我的理论,我删除了嵌套并尝试使mkdir只创建一个目录,并且它产生与以前相同的错误。 Although it's owned by Apache, and even if I set it to 777, it throws back permission issues. 虽然它由Apache拥有,即使我将其设置为777,它也会抛出权限问题。
Could be that although you have 755/777 permissions, SELinux is blocking httpd from writing/creating dirs. 可能是因为你有755/777权限,SELinux阻止httpd编写/创建dirs。
Try: 尝试:
chcon -R -t httpd_sys_content_t /path/to/www
chcon -R -t httpd_sys_content_rw_t /path/to/www/dir/for/rw
Further info: http://wiki.centos.org/TipsAndTricks/SelinuxBooleans 更多信息: http : //wiki.centos.org/TipsAndTricks/SelinuxBooleans
Not sure but your Centos's PHP binaries may have broken file permissions. 不确定,但Centos的PHP二进制文件可能已经破坏了文件权限。 There are two ways to fix this up. 有两种方法可以解决这个问题。
According to DRU Response 根据DRU Response
This issues is due to SELINUX. 这个问题是由SELINUX引起的。 Use bellow command 使用bellow命令
chcon -R -t httpd_sys_content_rw_t /path/to/www/dir/for/rw chcon -R -t httpd_sys_content_rw_t / path / to / www / dir / for / rw
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.