[英]Force owner of all files in the folder “/var/www” are user www-data
[英]Www-data User to Access files/folder outside of /var/www/
好的,有沒有辦法讓PHP用戶(www-data)訪問服務器的其他部分,例如/ home / username / another_folder / ?? 提前致謝。
將
編輯:我只是將www數據添加到另一個組? 或類似的東西,還是有另一種方式?
您可以創建另一個組並將www-data
(如果您的Web服務器在www-data
用戶下運行)添加到該組,然后將該組分配給您希望可訪問的所有文件。
或者,如果您只需要讀取權限,並且系統上的其他用戶對您的文件具有讀取權限不是問題,那么只需更改文件的權限(在其他位置)即可獲得other
的讀取權限。 例如,您的目錄為775
,文件為644
。
請記住,即使您的Web服務器用戶具有訪問這些文件的權限,您也無法在文檔根目錄以外的位置(例如/ var / www)提供頁面。
但是,如果為Web服務器配置“別名”或“虛擬主機”,則可以將其他位置設置為默認文檔根目錄,可通過HTTP請求訪問。
但是,根據您的文檔根目錄並由Web服務器執行的PHP文件,如果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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.