gpt4 book ai didi

NFS 文件夹的 PHP is_writable false 尽管可以写入文件

转载 作者:可可西里 更新时间:2023-11-01 12:56:24 25 4
gpt4 key购买 nike

抱歉,我不确定这是否是正确的论坛,因为我不知道问题的原因,我正在面对。

我在 Raspbian (Stretch 9) 上安装了 NextCloud,并将数据目录移动到挂载的 NFS 文件夹中。当我尝试访问 NextCloud 时,收到错误消息“数据目录不可写”。

所以我更深入地挖掘,最终可以将问题隔离到 PHP7.0 和 NFS 之间的交互:

由于某种原因,应用程序可以写入目录,但 is_writable 返回 false。

我创建了以下 PHP 脚本:

<?php
$dirname = '/var/churros/data/nextcloud/';
//$dirname = '/tmp/';

$myfile = fopen($dirname.'newfile.txt', "w") or die("Unable to open file!");
$txt = "John Doe\n";
fwrite($myfile, $txt);
fclose($myfile);
echo nl2br("File ".$dirname."newfile.txt written\n");

if (touch($dirname.'/chkpt.tmp')) {
echo nl2br("touch(".$dirname."/chkpt.tmp) successful\n");
} else {
echo nl2br("touch(".$dirname."/chkpt.tmp) failed\n");
}

if (is_writable($dirname)) {
echo 'Directory '.$dirname.' is writable';
} else {
echo 'Directory '.$dirname.' is not writable';
}

phpinfo();
?>

结果是

我的 NFS 安装为

192.168.1.100:/volume1/pidata/donut on /var/churros type nfs4 (rw,relatime,vers=4.0,rsize=131072,wsize=131072,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=192.168.1.103,local_lock=none,addr=192.168.1.100)

显然用户映射和访问权限是正确的:

namei -l /var/churros/web/nextcloud/
f: /var/churros/web/nextcloud/
drwxr-xr-x root root /
drwxr-xr-x root root var
drwxr-xr-x root root churros
drwxr-xr-x www-data www-data web
drwxrwxr-x www-data www-data nextcloud

在命令行上,作为用户 www-data,我可以访问该目录并向其写入数据。

最后,盒子上安装/启用 SELinux。

那么:知道为什么 PHP is_writable 在 NFS 目录上失败或者我如何调试这个 PHP 函数吗?

最佳答案

问题可能是 unix 用户 id 对于 2 个不同系统的用户“www-data”是不同的。

详细信息,来自 php src ,你可以看到:

反过来:

is a convenience wrapper for virtual_access()

is thread safe wrapper around the access() function that takes per-thread virtual working directories into account.

最后,寻找access() doc :

The access() function checks the file named by the pathname pointed to by the path argument for accessibility according to the bit pattern contained in amode, using the real user ID in place of the effective user ID and the real group ID in place of the effective group ID.

还有在 access() linux documentation ,它指出:

access() may not work correctly on NFS file systems with UID mapping enabled, because UID mapping is done on the server and hidden from the client, which checks permissions. Similar problems can occur to FUSE mounts.

尝试:

var_dump(stat('nfs-filename'));

并查看您得到的是哪个 uid

引用:

Similar issue with php session in nfs

关于NFS 文件夹的 PHP is_writable false 尽管可以写入文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50707811/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com