English 中文(简体)
Www-data用户访问/var/www/以外的文件/文件夹。
原标题:Www-data User to Access files/folder outside of /var/www/

好的,PHP用户(www-data)是否有办法访问服务器的其他部分,例如/home/username/another_folder/?谢谢提前。

Would you like to provide more context for the word "Will" in order for me to give a more accurate translation? "Will" can have multiple meanings and translations in Chinese depending on the context.

编辑:我只需将www-data添加到另一个组中吗?还是类似于这样的方式,还是有其他方式?

最佳回答

你可以创建另一个群组,并将 www-data(如果您的 Web 服务器在 www-data 用户下运行)添加到此群组中,然后将此群组分配给您希望可以访问的所有那些文件。

或者如果您只需要读取权限,并且其他系统用户可以读取您的文件不是问题,则只需更改文件(在其他位置)的权限以使other获得读取权限。例如,对于您的目录,使用775 ,对于您的文件,则使用644

请记住,即使您的Web服务器用户具有访问这些文件的权限,您也不能在文档根目录之外的位置(例如/var/www)提供网页。

但是如果您为您的Web服务器配置“别名”或“虚拟主机”,您可以使其他地方可通过HTTP请求访问而不是您的默认文档根目录。

但是,如果PHP文件位于文档根目录下并由Web服务器执行,则如果Web服务器用户具有足够的权限,则可以阅读文档根目录外部文件的内容。

// file permissoins
/tmp/shared_by_all.txt -> 644
/home/user1 -> 751 or 755
/home/user1/shared_by_all.txt -> 644
/home/secureuser -> 750
/home/secureuser/myfile.txt -> 640 (or even 644 because of the containing directory permissions, other can not even enter the directory tree. so file is not accessible)


// file: /var/www/read_file.php
<?php
    echo file_get_contents( /tmp/shared_by_all.txt ); // ok!
    echo file_get_contents( /home/user1/shared_by_all.txt ); // ok!;
    echo file_get_contents( /home/secureuser/myfile.txt ); // fail!;
?>
问题回答

您可以将文件夹的群组所有权(chgrp)更改为www-data(如果www-data是它自己的群组)。

你可以更改那个文件夹的用户所有权(chown)并chmod它,使多个用户可以访问它。(就像farzad所说的那样)

你可以创建一个名为“me_and_web”的组,只有“username”和“www-data”是其成员,并使用命令 chgrp -R me_and_web /home/username/another_folder





相关问题
Signed executables under Linux

For security reasons, it is desirable to check the integrity of code before execution, avoiding tampered software by an attacker. So, my question is How to sign executable code and run only trusted ...

encoding of file shell script

How can I check the file encoding in a shell script? I need to know if a file is encoded in utf-8 or iso-8859-1. Thanks

How to write a Remote DataModule to run on a linux server?

i would like to know if there are any solution to do this. Does anyone? The big picture: I want to access data over the web, using my delphi thin clients. But i´would like to keep my server/service ...

How can I use exit codes to run shell scripts sequentially?

Since cruise control is full of bugs that have wasted my entire week, I have decided the existing shell scripts I have are simpler and thus better. Here is what I have so far svn update /var/www/...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

热门标签