PHP: fopen() Permission denied(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.html或 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
但是,如果您使用的是 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() 权限被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PHP:fopen() 权限被拒绝
基础教程推荐
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01
- PHP 守护进程/worker 环境 2022-01-01
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01
- 如何在 XAMPP 上启用 mysqli? 2021-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01
- HTTP 与 FTP 上传 2021-01-01
- 使用 PDO 转义列名 2021-01-01