简体   繁体   中英

php to write a file as root user

I have my script running on plesk latest version and plesk does not have write permissions. 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. 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. 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 :

1.you have to log in to your server with SSH

2.find the name of your web server username

3.Give permissions to web server with (chmod, chown) for the directory where you want to write data

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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