简体   繁体   English

php以root用户身份写入文件

[英]php to write a file as root user

I have my script running on plesk latest version and plesk does not have write permissions. 我的脚本在plesk最新版本上运行,而plesk没有写权限。 I have to write a configuration file with the values from database. 我必须使用数据库中的值编写一个配置文件。

I tried the following, 我尝试了以下方法

$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);

The php variables are coming from database and I need to update _conn.php file with those variables to run the website. php变量来自数据库,我需要使用这些变量更新_conn.php文件才能运行网站。 I cannot do that because of permission issue. 由于权限问题,我无法这样做。

Is there any other way to do that? 还有其他方法吗? I read somewhere that we can do that as a apache or root user. 我读过某个地方,我们可以以apacheroot用户的身份进行操作。 But I am not sure what does that mean. 但是我不确定这是什么意思。 Help please.. 请帮助..

Depending on the linux distribution that you installed in your VPS you will have to type different commands but those steps remain the same : 根据在VPS中安装的Linux发行版,您将不得不键入不同的命令,但是这些步骤保持不变:

1.you have to log in to your server with SSH 1.您必须使用SSH登录到服务器

2.find the name of your web server username 2.找到您的Web服务器用户名的名称

3.Give permissions to web server with (chmod, chown) for the directory where you want to write data 3.使用(chmod,chown) 授予要写入数据目录的Web服务器权限

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM