Www-data User to access files / folder outside / var / www /

Well, is there a way for a PHP user (www-data) to access other parts of the server, for example, / home / username / another _folder / ?? Thanks at Advance.

Will

EDIT: Am I just adding www data to another group? Or something like that, or is there another way?

+3
source share
2 answers

You can create another group and add to this group www-data(if your web server runs under www-data), and then assign this group to all the files that you want to receive.

, , , , ( ), other. , 775 644 .

, , (,/var/www), - .

, "" " " -, , root- , HTTP-.

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!;
?>
+3

(chgrp) www- ( www-data - .)

(chown) chmod, . ( )

( "me_and_web" ), " " "www-data" chgrp -R me_and_web /home/username/another_folder

+2

Source: https://habr.com/ru/post/1731742/


All Articles