PHP 写入权限 - FC13
我最近安装了 FC13,并尝试在 PHP 代码中编写一种机制,将收集的数据缓存到特定目录中(出于我们的目的,我们将其称为 /var/www/html/_php_resources/cache)。
我将文件复制到 /var/www/html 目录,然后运行 chown -R apache:apache /var/www/html/* 和 chmod a+w /var/www /html/_php_resources/cache 新数据。目前,为了方便起见,我只是使用全局写入权限。稍后我会调整权限。
当我尝试使用 chmod 或 mkdir PHP 函数时,我最终得到:
警告:chmod():/var/www/html/_include/php/CacheInit.php 中的权限被拒绝
或
警告:mkdir():/var/www/html/_include/php/CacheInit.php 中的权限被拒绝
现在,当我禁用 SELinux 时,一切正常。问题是我宁愿不禁用 SELinux 并实际正确设置权限,以便我可以将其移植到某人没有此类明确控制权的服务器。
举个例子:我的个人站点主机允许我设置目录的读/写权限,但不允许更改 SELinux 策略。
仅供参考:
- uname -r = 2.6.34.7-56.fc13
- *php -version * = PHP 5.3.3
- rpm -qa | grep httpd = httpd-2.2.16-1.fc13
有人有什么建议吗?
I have recently installed FC13 and am attempting to write a mechanism in my PHP code that caches gathered data into a specific directory (for our purposes here, let's call it /var/www/html/_php_resources/cache).
I copy my files over to the /var/www/html directory and then run chown -R apache:apache /var/www/html/*
and chmod a+w /var/www/html/_php_resources/cache
on the new data. For right now I am just using the global write permission for convenience. I will tweak the permissions later.
When I attempt to use the chmod
or mkdir
PHP functions I wind up with:
Warning: chmod(): Permission denied in /var/www/html/_include/php/CacheInit.php
or
Warning: mkdir(): Permission denied in /var/www/html/_include/php/CacheInit.php
Now, when I disable SELinux everything works just fine. The problem is that I would prefer not to disable SELinux and actually get the permissions set up correctly so that I can port it over to servers where someone does not have such explicit control.
As an example: my personal site host allows me to set read/write permissions on directories but will not allow for SELinux policy changes.
FYI:
- uname -r = 2.6.34.7-56.fc13
- *php -version * = PHP 5.3.3
- rpm -qa | grep httpd = httpd-2.2.16-1.fc13
Does anyone have any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我遇到了同样的问题,尝试从 php 中 mkdir 。谷歌上没有太多信息,但这是我发现的,我想这是正确的解决方案。必须标记 apache 应在其中创建目录的目录。
标签应该是“httpd_sys_script_rw_t”,我在这里找到了该信息: http://docs.fedoraproject.org/en-US/Fedora_Core/5/html/SELinux_FAQ/index.html#id672528
以下是标记目录的方法:
chcon -R -t httpd_sys_script_rw_t < ;目录>
参考此处: http://www .centos.org/docs/5/html/Deployment_Guide-en-US/rhlcommon-chapter-0017.html
希望这可以帮助那里的人。
I had the same problem, trying to mkdir from php. Not so much information on google but this is what I found and I guess this is the correct solution. One have to label the dir in which apache should create directories.
Label should be "httpd_sys_script_rw_t" and I found that info here: http://docs.fedoraproject.org/en-US/Fedora_Core/5/html/SELinux_FAQ/index.html#id672528
Here's how to label the dir:
chcon -R -t httpd_sys_script_rw_t <dir>
Reference somewhere here: http://www.centos.org/docs/5/html/Deployment_Guide-en-US/rhlcommon-chapter-0017.html
Hope this help someone out there.