Web Hosting Talk







View Full Version : chown functions in php


galacnet
10-06-2004, 08:22 AM
Does anyone know how to get a php script to chown a file to another user?

I used
chown ("filename", username);
But I got this error

Warning: chown(): Operation not permitted in /home/sites/site2/web/form.php on line 66

I then tried
exec (chown -R username filename);
No errors but it doesn't change anything at all at all....

Also tried shell_exec after reading the php manual but also no luck with that....
The CHMOD functions work under the same coding as above though but not the CHOWN...

Please help
I am running php 4.3.8
Thanks

Burhan
10-06-2004, 09:40 AM
chown requires superuser access.

"Only the superuser may change the owner of a file." @ http://www.php.net/chown

galacnet
10-06-2004, 10:11 AM
And how do I give php superuser access?
And what are the risk involved??

inimino
10-06-2004, 10:26 AM
That would be a Bad Idea.

Why do you need to chown a file through PHP? There should be no reason for it in normal use. What's the purpose of your script?

galacnet
10-06-2004, 10:30 AM
Because the script creates files and directories and under the "httpd" user.
This is causing my server to go down with "flex scanner" errors.

After manually changing the ownership to an admin user for that site the problem stopped. But came back when I allowed it to create files under the "httpd" user again.

utsn
10-06-2004, 11:29 AM
Originally posted by galacnet
And how do I give php superuser access?
And what are the risk involved??

The risk is too high to be worth it.
Every script that has a bugs gonna get root access. You don't want this to happen.

Cheers,
Matt

galacnet
10-06-2004, 11:32 AM
Yes... after some considerations is really too risky.
I will just have to deploy someone to run SSH and change it manually :P

Thanks for the help.

gogocode
10-07-2004, 04:53 AM
Originally posted by galacnet
Yes... after some considerations is really too risky.
I will just have to deploy someone to run SSH and change it manually :P


Or just create them with the permissions such that the user trying to read/write the files httpd is creating can access them.