我知道这是一个有很多线程的常见错误,但我厌倦了搜索,但我仍然没有解决它.当我尝试运行函数 file_put_contents 时,我收到以下错误:
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
我已经做了最常见的回答,把nurses文件夹和test.txt文件的权限改成777.那个不行.
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.
我目前正在全新安装最新的 CentOS 7 服务器.
I'm currently on a fresh install of the latest CentOS 7 server.
我发现如果我通过控制台运行php脚本:
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.
最好的问候!
好的,我找到了问题:selinux
Ok, I found the issue: selinux
解决方案如下:http://kb.sp.parallels.com/en/11142
万一页面宕机:
症状
在您更改存储网站内容的默认目录(例如,更改为/home")后,您将无法通过 Web 访问子域和其他网站的内容.
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.
原因
如果SELinux 在Enforcement"模式下工作,则会出现此问题.在这种模式下,网站的 webroot 目录和其中的子域具有不同的权限,您的 Web 服务器无法访问它们.运行这个命令:
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
输出应该是:Enforcing
分辨率
禁用SELinux支持:在任意编辑器中打开文件/etc/selinux/config并找到这一行:
Disable SELinux support: Open the file /etc/selinux/config in any editor and find this row:
SELINUX=<value>
改成:
SELINUX=disabled
如果找不到此文件,请在任意编辑器中打开文件/boot/grub/grub.conf 并将参数 selinux=0 添加到 Grub Boot Loader:
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 上的流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!