无法在CentOS 7上的PHP中打开file_put_contents上的流 [英] Failed to open stream on file_put_contents in PHP on CentOS 7
问题描述
我知道这是一个有许多线程的常见错误,但是我已经厌倦了搜索,但仍然没有解决它.当我尝试运行功能 file_put_contents 时,出现以下错误:
Warning: file_put_contents(test.txt): failed to open stream: Permission denied in /var/www/html/nurses/adminWriter.php on line 29
我已经做了最常见的回答,将 nurses 文件夹和 test.txt 文件的权限更改为777.这没有用./p>
我目前正在全新安装最新的CentOS 7服务器.
我发现,如果我通过控制台运行php脚本:
# php /var/www/html/nurses/adminWriter.php
它工作得很好,只有在通过浏览器运行它时才会出现错误,但我确实需要以这种方式运行.
最诚挚的问候!
好,我发现了问题:selinux
以下是解决方案: http://kb.sp.parallels.com/en/11142
如果页面出现故障:
症状
更改默认目录以存储网站内容(例如,更改为"/home")后,您将无法通过Web访问子域和其他网站的内容.
原因
如果 SELinux 在"实施"模式下工作,则会出现此问题.在这种模式下,网站和其中的子域的webroot目录具有不同的权限,并且您的Web服务器无法访问它们.运行以下命令:
# getenforce
输出应为:执行
解决方案
禁用 SELinux 支持:在任何编辑器中打开文件/etc/selinux/config 并找到以下行:
SELINUX=<value>
将其更改为:
SELINUX=disabled
如果找不到此文件,请在任何编辑器中打开文件/boot/grub/grub.conf并将参数 selinux = 0 添加到Grub引导加载程序:
title SE-Linux Test System
root (hd0,0)
kernel /boot/vmlinuz-2.4.20-selinux-XXXXXXXXXX ro root=/dev/hda1 nousb selinux=0
#initrd /boot/initrd-2.4.20-selinux-XXXXXXXXXX.img
重新引导服务器以应用更改. 如果您不想重新启动,请运行以下命令:
# setenforce 0
I know this is a common bug with many threads but I'm tired of searching and I still haven't solved it. When I try to run the function file_put_contents I get the following error:
Warning: file_put_contents(test.txt): failed to open stream: Permission denied in /var/www/html/nurses/adminWriter.php on line 29
I've already done the most common answer, change the permissions of the nurses folder and the test.txt file to 777. That didn't work.
I'm currently on a fresh install of the latest CentOS 7 server.
I've found that if I run the php script through the console:
# php /var/www/html/nurses/adminWriter.php
It works just fine, I get the error only when running it through the browser, but I really need to run it this way.
Best Regards!
Ok, I found the issue: selinux
Here's the solution: http://kb.sp.parallels.com/en/11142
In case the page goes down:
Symptoms
After you change the default directory to store website content (say, to "/home"), you are unable to access the content of subdomains and additional websites over the Web.
Cause
This problem occurs if SELinux works in "Enforcement" mode. In this mode, webroot directories for websites and subdomains inside them have different permissions, and your web server fails to access them. Run this command:
# getenforce
The output should be: Enforcing
Resolution
Disable SELinux support: Open the file /etc/selinux/config in any editor and find this row:
SELINUX=<value>
Change it to:
SELINUX=disabled
If you cannot find this file, open the file /boot/grub/grub.conf in any editor and add the parameter selinux=0 to the Grub Boot Loader:
title SE-Linux Test System
root (hd0,0)
kernel /boot/vmlinuz-2.4.20-selinux-XXXXXXXXXX ro root=/dev/hda1 nousb selinux=0
#initrd /boot/initrd-2.4.20-selinux-XXXXXXXXXX.img
Reboot the server to apply the changes. If you do not want to reboot, run this command:
# setenforce 0
这篇关于无法在CentOS 7上的PHP中打开file_put_contents上的流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!