簡體   English   中英

php以root用戶身份寫入文件

[英]php to write a file as root user

我的腳本在plesk最新版本上運行,而plesk沒有寫權限。 我必須使用數據庫中的值編寫一個配置文件。

我嘗試了以下方法

$pathconn =  $_SERVER['DOCUMENT_ROOT']."/mysite/_conn.php";
if(file_exists($pathconn)){
    chmod($pathconn, 0777);
}
$file_contents = file_get_contents($pathconn);
$file_contents = str_replace("webuser_admin", $username."_admin", $file_contents);
$file_contents = str_replace("webpass", $mysql_password, $file_contents);
$file_contents = str_replace("web_db", $username."_ss", $file_contents);
file_put_contents($pathconn, $file_contents);

php變量來自數據庫,我需要使用這些變量更新_conn.php文件才能運行網站。 由於權限問題,我無法這樣做。

還有其他方法嗎? 我讀過某個地方,我們可以以apacheroot用戶的身份進行操作。 但是我不確定這是什么意思。 請幫助..

根據在VPS中安裝的Linux發行版,您將不得不鍵入不同的命令,但是這些步驟保持不變:

1.您必須使用SSH登錄到服務器

2.找到您的Web服務器用戶名的名稱

3.使用(chmod,chown) 授予要寫入數據目錄的Web服務器權限

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM