PHP:fopen() 权限被拒绝 [英] PHP: fopen() Permission denied

查看:35
本文介绍了PHP:fopen() 权限被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对这段代码感到困惑:

I am confused with this code:

test.php:

fopen('test.txt','a+');

当我执行它时,我收到一个错误:

when I execute it, I get an error:

Warning: fopen(test.txt): failed to open stream:
     Permission denied in /var/www/html/yuelu3/mobile/text.php on line 2

test.txt:

-rwxrwxrwx. 1 jt jt     87 10月  7 20:58 test.txt

问题出在哪里?

非常感谢!我已经找到问题了,我用的是FC13,因为SELinux的保护,一些动作被拒绝了.所以,我只需要摆脱保护.

Thanks a lot!I have found the problem,I use FC13,because of the protect of SELinux,some action is denied.So, I just need to get rid of the protect.

推荐答案

这个问题也可能是因为启用了 SELinux.这可以使用以下方法解决:

This issue can also be a result of having SELinux enabled. This can be solved using:

chown -R apache:apache /var/www/html/directory_to_write
chcon -R -t httpd_sys_content_t /var/www/html/directory_to_write
chcon -R -t httpd_sys_rw_content_t /var/www/html/directory_to_write

您可以在 https://web.archive.org/web/20150927091100/https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Managing_Confined_Services/sect-Managing_Confined_Services-The_Apache_HTTP_Server-Types.htmlhttps://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/managing_confined_services/sect-managing_confined_services-the_apache_http_server-types

但是,如果您使用的是 Redhat 8 或更新版本,则可能需要关注 https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/using_selinux/configuring-selinux-for-applications-and-services-with-non-standard-configurations_using-selinux#customizing-the-selinux-policy-for-the-apache-http-server-in-a-non-standard-configuration_configuring-selinux-for-applications-and-services-with-non-standard-configurations

However if you are on anything like Redhat 8 or newer, you might want to follow https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/using_selinux/configuring-selinux-for-applications-and-services-with-non-standard-configurations_using-selinux#customizing-the-selinux-policy-for-the-apache-http-server-in-a-non-standard-configuration_configuring-selinux-for-applications-and-services-with-non-standard-configurations

这篇关于PHP:fopen() 权限被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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