我在 CentOS 7 上運行服務器apache。組 apache 具有775權限/var/www/html
當我執行想要在其中創建新檔案的 PHP 檔案時root dir (/var/www/html/)出現以下錯誤
Warning: file_put_contents(file.bin): failed to open stream: Permission denied in /var/www/html/file.php
PHP代碼:
<?php
ini_set('display_errors', 'on');
$file = 'file.bin';
$content = "Content";
file_put_contents($file, $content);
?>
我將使用更多資料更新問題,但由于我是新手,所以我對除錯服務器錯誤了解不多。
我嘗試了什么:
為了執行腳本(php ..),我看到用戶是 apache,所以我在 /var/www/html/ 上賦予了“apache”所有權
試穿(并
777在./html對 755 不起作用后撤消操作)也試過
cd /var/www/htmlchmod -R 775 .(來自評論)
uj5u.com熱心網友回復:
很有可能,問題出在selinux. selinux如果您使用命令(從根目錄)關閉:
setenforce 0
selinux一切都會正常作業,您需要使用命令(從根目錄)打開:
setenforce 1
并運行命令:
chcon -R -t httpd_sys_rw_content_t /your/path
一切都必須作業。如果這種方法沒有幫助,我建議你閱讀這個問題的答案。有一個更靈活selinux 設定的答案(使用 using sudo semanage fcontext)。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/437240.html
