views:

188

answers:

3

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

+5  A: 

Most likely, if run from apache, the user that apache is running as.

Jordan S. Jones
There are lots of scenarios where this is not most likely :)
Tim Post
@Tim Aye, that is true.
Jordan S. Jones
+2  A: 

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.

Tim Post
A: 

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
jonescb
No, apache will _not_ always own the files. There is such a thing as suexec :) When you copy a file as root, _root_ owns the destination file, as _root_ created it.
Tim Post
kool, I ran <code>echo exec('whoami');</code> and it returned my ftp user. thanks.
Ken