我与一家托管公司共享虚拟 Linux 主机,我只知道使用 CPANEL,但我不知道使用 CLI。最近由主机迁移到 PHP 5.2 到 PHP 5.3.2 在目录中使用 file_put_contents 时会抛出权限被拒绝错误写入文件。所以我想在我的能力范围内尝试一些调试的东西
// Assume my file is
// here /home/myhostaccount/public_html/mytest where mytest is 755
// Assume migrated.log exists in the above directory and migrated.log is 644
$file1 = "migrated.log" // this is migrated file which is denied write
$file2 = "dummytest.log" // this file I created for debug, it allows write
writeme($file1,"This file existed before in 5.2 and was writeable, but fails to do a write after migration ");
// permission denied error failed to write BUT works if file forced to 646
writeme($file2,"This is created file by Me for Debugging ");
// works - writes just for the default 644
function writeme($file ,$data) {
$result = file_put_contents($file , $data, LOCK_EX);
if ($result === false) {
echo "failed to write to $file"; echo "<br/>";
}else{
echo "successfully written $result bytes to $file <br/>";
}
}
接下来我想我会检查文件所有者,因此
print_r(posix_getpwuid(fileowner($file1)));
echo "<br/><br/>";
print_r(posix_getpwuid(fileowner($file2)));
我得到输出
Array ( [name] => myhostaccount [passwd] => x [uid] => 1083 [gid] => 1083 [gecos] => [dir] => /home/myhostaccount [shell] => /bin/bash )
Array ( [name] => nobody [passwd] => x [uid] => 99 [gid] => 99 [gecos] => Nobody [dir] => / [shell] => /sbin/nologin )
首先,我不是一个很好的管理员来理解这个完整的输出,但我很惊讶为什么有两个不同的东西
我的问题是
a) 为什么同一目录中的文件会以不同的所有者身份运行 1) myhostaccount 2) 没有人
b)为什么没有人能够使用 644 成功写入,而 myhostaccount 失败但只能使用 646 写入
c) 问题出在哪里?在我这边......或......在托管方面
d)如果必须解决我应该做的事情,或者如果与他们在一起,我应该要求他们做
请帮忙。
问候