代码之家  ›  专栏  ›  技术社区  ›  willbeeler

Www数据用户访问/var/Www之外的文件/文件夹/

  •  3
  • willbeeler  · 技术社区  · 16 年前

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

    编辑:我是否只是将www数据添加到另一个组??或者类似的,或者有其他的方法吗?

    2 回复  |  直到 16 年前
        1
  •  4
  •   Buttle Butkus    9 年前

    您可以创建另一个组并添加 www-data (如果您的Web服务器运行在 www数据

    或者,如果您只需要读取权限,并且系统上的其他用户对您的文件没有读取权限,则只需更改您的文件(在其他位置)的权限,即可对您的文件具有读取权限 other . 例如 775 为您的目录和 644 为您的文件。

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

    但是,如果为web服务器配置“别名”或“虚拟主机”,则可以通过HTTP请求访问默认文档根以外的位置。

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

    // 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!;
    ?>
    
        2
  •  2
  •   poundifdef    16 年前

    您可以更改组所有权( chgrp )将文件夹中的内容添加到www数据(如果www数据是其自己的组。)

    您可以更改该文件夹的用户所有权( chown )及 chmod 它允许多个用户访问它(正如法扎德所说)

    chgrp -R me_and_web /home/username/another_folder