简体   繁体   中英

Who owns a php exec tar extracted file?

As far as file permissions are concerned, when you use a php script to unzip a tar file, who is the "owner" user of the files created?

I'm wondering if its my ftp user because I uploaded the script file? Or does apache own the file? I know their are flags to be set to preserve the original permissions which I don't want (files where created and archived by someone else). I want my user to be the creater/owner of the files.

PS Its a cloud environment. Below is the code I uploaded. I executed by visiting the page in a browser. I can change file permissions in Dreamweaver... Does that mean I am owner?

exec('wget http://wordpress.org/latest.tar.gz '); exec('tar -xzvf latest.tar.gz');

最有可能的是,如果从apache运行,那么apache正在运行的用户。

Whatever user runs PHP. Its either the web server's system user name, or the owner of the webroot (through suexec). If owned by the server, its likely nobody or www-data .

What matters most is what user PHP (server side) is running as. Try this to find out.

You can do echo shell_exec('whoami'); And that will output the name of the user. For me, it outputted apache

And yes, apache will own the files. For example, if you do something like this as root:

root@localhost# cp /home/user/foo /home/user/foo2
root@localhost# ls -l /home/user
-rw-rw-r--  1 user user       232 Apr  12 12:00 foo
-rw-rw-r--  1 root root       232 Apr  12 12:01 foo2

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