未能打开PHP中的file_put_contents的流,这是CentOS 7。

时间:2023-01-16 20:37:32

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:

我知道这是一个常见的有很多线程的bug,但是我已经厌倦了搜索,我仍然没有解决它。当我尝试运行函数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

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.

我已经做了最常见的回答,更改了护士文件夹的权限和测试。txt文件到777。没有工作。

I'm currently on a fresh install of the latest CentOS 7 server.

我现在正在重新安装最新的CentOS 7服务器。

I've found that if I run the php script through the console:

我发现,如果我通过控制台运行php脚本:

# 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!

最好的问候!

2 个解决方案

#1


9  

chcon -Rv --type=httpd_sys_rw_content_t /dir

This may help,rather than turn off the selinux.

这可能会有所帮助,而不是关闭selinux。

#2


6  

Ok, I found the issue: selinux

好的,我发现了一个问题:selinux。

Here's the solution: http://kb.sp.parallels.com/en/11142

解决方案: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.

在您更改了默认目录以存储网站内容(比如,to“/home”)之后,您就无法访问子域的内容,也无法访问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:

如果SELinux在“强制”模式下工作,则会出现此问题。在这种模式下,webroot目录中的网站和子域具有不同的权限,而您的web服务器无法访问它们。运行这个命令:

# getenforce

The output should be: Enforcing

输出应该是:强制执行。

Resolution

决议

Disable SELinux support: Open the file /etc/selinux/config in any editor and find this row:

禁用SELinux支持:在任何编辑器中打开文件/etc/selinux/config,找到这一行:

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:

如果您找不到这个文件,请打开文件/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

Reboot the server to apply the changes. If you do not want to reboot, run this command:

重新启动服务器以应用更改。如果您不想重新启动,运行以下命令:

# setenforce 0

#1


9  

chcon -Rv --type=httpd_sys_rw_content_t /dir

This may help,rather than turn off the selinux.

这可能会有所帮助,而不是关闭selinux。

#2


6  

Ok, I found the issue: selinux

好的,我发现了一个问题:selinux。

Here's the solution: http://kb.sp.parallels.com/en/11142

解决方案: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.

在您更改了默认目录以存储网站内容(比如,to“/home”)之后,您就无法访问子域的内容,也无法访问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:

如果SELinux在“强制”模式下工作,则会出现此问题。在这种模式下,webroot目录中的网站和子域具有不同的权限,而您的web服务器无法访问它们。运行这个命令:

# getenforce

The output should be: Enforcing

输出应该是:强制执行。

Resolution

决议

Disable SELinux support: Open the file /etc/selinux/config in any editor and find this row:

禁用SELinux支持:在任何编辑器中打开文件/etc/selinux/config,找到这一行:

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:

如果您找不到这个文件,请打开文件/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

Reboot the server to apply the changes. If you do not want to reboot, run this command:

重新启动服务器以应用更改。如果您不想重新启动,运行以下命令:

# setenforce 0