Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 权限设置为777,文件仍不可写_Php_Apache_Mod Rewrite - Fatal编程技术网

Php 权限设置为777,文件仍不可写

Php 权限设置为777,文件仍不可写,php,apache,mod-rewrite,Php,Apache,Mod Rewrite,我已将文件权限设置为777,但无法使用PHP写入该文件 我可以在我的FTP客户端中清楚地看到该文件具有0777权限,并且当我这样做时: echo (true === is_writable('file.txt')) ? 'yes' : 'no'; 我得到“不” 我还尝试: echo (true === chmod('file.txt', 0777)) ? 'yes' : 'no'; 同样的结果 目录列表如下所示: public_html public 0777

我已将文件权限设置为777,但无法使用PHP写入该文件

我可以在我的FTP客户端中清楚地看到该文件具有0777权限,并且当我这样做时:

echo (true === is_writable('file.txt')) ? 'yes' : 'no';
我得到“不”

我还尝试:

echo (true === chmod('file.txt', 0777)) ? 'yes' : 'no';
同样的结果

目录列表如下所示:

public_html
    public          0777
        css         0755
        js          0755
        file.txt    0777
public_html
    public
        file.txt  0777
$ lsattr /etc/hosts
-------------e- /etc/hosts
我使用.htaccess文件将所有流量重定向到public子文件夹。当然,我已将该文件排除在重写之外(可以从我选中的浏览器访问该文件):


为什么会这样?

您必须在创建文件后立即对其进行chmod

function Doo_Chmod($path, $chmod = null)
{
    if (file_exists($path) === true)
    {
        if (is_null($chmod) === true)
        {
            $chmod = (is_file($path) === true) ? 644 : 755;

            if (in_array(get_current_user(), array('apache', 'httpd', 'nobody', 'system', 'webdaemon', 'www', 'www-data')) === true)
            {
                $chmod += 22;
            }
        }

        return chmod($path, octdec(intval($chmod)));
    }

    return false;
}

我猜Apache运行的用户/组与拥有该文件的用户/组不同。在这种情况下,文件本身需要是
0777

public
仅当您计划使用PHP将文件添加到文件夹时才需要
0777
。即使文件夹本身不是
0777
,如果该文件是,并且该文件夹对于用户至少有
5
read/execute
),您也应该能够写入该文件

最后,您的文件树应该如下所示:

public_html
    public          0777
        css         0755
        js          0755
        file.txt    0777
public_html
    public
        file.txt  0777
$ lsattr /etc/hosts
-------------e- /etc/hosts
当然,您不能使用PHP更改这些权限,但您可以从FTP客户端进行更改

如果它仍然不工作,PHP可能正在安全模式下运行,或者您可能正在使用诸如PHPSuhosin之类的扩展。将文件的所有者更改为运行脚本的同一用户/组可能会获得更好的结果

要获取执行用户的用户/组id,可以使用以下命令:

<?php
echo getmyuid().':'.getmygid(); //ex:. 0:0
?>

在opencart中,我在安装vqmod并授予所有必要的权限后遇到了这个错误

经过一点研究,找到了它

“MODS缓存路径不可写”实际上指的是vqmod文件夹本身,而不是缓存文件夹

sudo chmod -R 777 vqmod 

在您的根目录中……

与上面的问题没有严格的关系,但是,我将把它放在这里供将来的访问者使用,因为我是来这里阅读标题的。 发件人:

文件属性 除了控制用户和组读、写的文件模式位之外 和执行权限,多个文件系统支持文件属性 允许进一步自定义允许的文件操作。这 第节介绍其中一些属性以及如何使用它们

警告:默认情况下,cp、rsync、, 以及其他类似的项目。chattr和lsattr

对于ext2和ext3文件系统,e2fsprogs包包含 程序lsattr和chattr列出并更改文件的属性, 分别地虽然有些文件系统不受所有文件系统的尊重,但 可用属性包括:

a: append only
c: compressed
d: no dump
e: extent format
i: immutable
j: data journalling
s: secure deletion
t: no tail-merging
u: undeletable
A: no atime updates
C: no copy on write
D: synchronous directory updates
S: synchronous updates
T: top of directory hierarchy
例如,如果要在某个文件上设置不可变位,请使用 以下命令:

#chattr+i/path/to/file

要删除文件上的属性,只需将+更改为-

对于没有其他属性的文件,
lsattr
如下所示:

public_html
    public          0777
        css         0755
        js          0755
        file.txt    0777
public_html
    public
        file.txt  0777
$ lsattr /etc/hosts
-------------e- /etc/hosts

您是否具有该文件夹的写入权限?能否提供该文件的目录列表?有可能你不是主人吗?另外,这可能是FTP服务器配置问题。你为什么要使用===运算符?你可以使用普通的文本编辑器或终端命令(touch)写入文件吗?@Daniel a.White:==运算符还检查类型是否相等,因为我们已经知道可写返回bool,那么它的效果应该与使用==I上传文件的效果相同。我不是在PHP中创建它的;当前用户是否与上载文件的FTP用户相同?如果没有,这就是你的问题,你需要用FTP客户端CHMOD它,然后你可以使用我上面发布的功能(或者手动CHMODs)。实际上它是一个共享托管环境,所以我没有访问shell的权限。但无论如何,谢谢你的回答。我已经决定修改我的脚本,以便它使用数据库来写入数据,而不是文本文件。现在它工作了。我只想补充一点,我已经设置了正确的所有者,并且我的文件仍然不可写。如本答案所述,原因是SELinux