即使将chmod设置为0777,Linux Server问题,PHP fopen文件也不可写

问题描述

这是我的简单代码

$dst = "otps/hello.txt";
echo $dst,file_exists($dst) ? ' exists' : ' does not exist',"\n";
echo $dst,is_readable($dst) ? ' is readable' : ' is NOT readable',is_writable($dst) ? ' is writable' : ' is NOT writable',"\n";
$fh = fopen($dst,'w');
if ( !$fh ) {
    echo ' last error: ';
    echo '<pre>';print_r(error_get_last());echo'</pre>';
}

我的当前目录设置为0777,但仍然是错误,我手动创建文件并将权限设置为0777,仍然是相同的错误

enter image description here

enter image description here

这里是输出

enter image description here

请注意,我已经在数字海洋上自行设置了VPS服务器。我尝试将整个目录和文件的chown更改为apache,root,nobody,但没有任何效果

解决方法

运行命令

setenforce 0

为我工作,不确定为什么:)