简体   繁体   English

PHP fopen() 权限被拒绝

[英]PHP fopen() Permission denied

I'm a PHP learner and I'm working with files but I can't open a file in my own server because there is a "permission denied" error.我是 PHP 学习者,我正在处理文件,但我无法在自己的服务器中打开文件,因为出现“权限被拒绝”错误。 I'm using fopen() function: fopen('file.txt', 'r+');我正在使用fopen() function: fopen('file.txt', 'r+');

I'm using Apache 2.4.37 and PHP 7.2.11 in a CentOS.我在 CentOS 中使用 Apache 2.4.37 和 PHP 7.2.11。 I've been searching a lot in the internet but nothing worked, I had installed fpm, I tried with other PHP version, I check that allow_url_fopen is turned on, I reinstalled PHP and Apache, I ensured all permissions are OK.我在互联网上搜索了很多,但没有任何效果,我已经安装了 fpm,我尝试了其他 PHP 版本,我检查了allow_url_fopen是否打开,我重新安装了 PHP 和 ZE9713AE04A052A81094ZF3 确保所有权限都正常I also install in a VM other CentOS but the problem was on it too, then I tried with Ubuntu and it worked perfectly but my server is running in CentOS.我还安装在其他 CentOS 的 VM 中,但问题也在它上面,然后我尝试使用 Ubuntu 并且它运行良好,但我的服务器在 CentOS 中运行。

Ok, I have searching all the day but finally I resolved it.好的,我整天都在搜索,但最后我解决了。 The problem was about SELinux.问题是关于 SELinux。

I don't know why but SELinux comes in enforcing mode by default but when I turned it off all was solved.我不知道为什么,但是 SELinux 默认进入强制模式,但是当我关闭它时,一切都解决了。 If you don't want to turn it off because security reasons you can set permissions but it's kind advanced for beginners users to understand.如果您出于安全原因不想将其关闭,您可以设置权限,但对于初学者用户来说这是一种高级理解。 I found how to set these permissions here: https://serverfault.com/a/819370我在这里找到了如何设置这些权限: https://serverfault.com/a/819370

If you don't want to fight against SELinux you can turn it off by editing /etc/sysconfig/selinux and put permissive (recommended) or disabled after SELINUX=如果你不想对抗 SELinux,你可以通过编辑/etc/sysconfig/selinux并在SELINUX=之后设置permissive (推荐)或disabled来关闭它

If you want to learn more about SELinux, DigitalOcean has an excellent posts about that: https://www.digitalocean.com/community/tutorial_series/an-introduction-to-selinux-on-centos-7如果你想了解更多关于 SELinux 的信息,DigitalOcean 有一篇关于这方面的优秀文章: https://www.digitalocean.com/community/tutorial_series/an-introduction-to-selinux-on-centos-7

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM