php以root用户身份编写文件

时间:2015-06-01 05:52:19

标签: php shell

我的脚本在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用户执行此操作。但我不确定这是什么意思。请帮助..

1 个答案:

答案 0 :(得分:0)

根据您在VPS中安装的Linux发行版,您必须键入不同的命令,但这些步骤保持不变:

1.您必须使用 SSH

登录服务器

2.找到您的网络服务器名称用户名

3.使用(chmod,chown)为要写入数据的目录的Web服务器权限