Forum Moderators: coopster

Message Too Old, No Replies

changing file ownership with PHP

         

elgolferisto

11:52 pm on Mar 25, 2005 (gmt 0)

10+ Year Member



I am writing a simple script that needs to create files and change their ownership. Using the chown() function in PHP, I cannot do this unless I am running chown as root. I am running as apache.

Initially, I thought I was stuck, but I know that there is some way to do this. Squirrelmail, for example, writes to files in users home directories (/home/$username), and looking at the ownership and permissions of these files shows that they are indeed owned by $username, with permissions 0600. What is a program like Squirrelmail doing that allows them to append to these files without changing the ownership or permissions of these files. That is, what is the best (safest), or at least a good (safe) way to gain root access and update these files?

ergophobe

4:44 pm on Mar 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Do you really want a script that is running from web root to get root privileges? That seems unwise to say the least.

Can you create a file in the directory in question and then delete the old one? Presumably the new file would be owned by apache and then you could do whatever you wanted with it.

When you log into the shell, do you have access to these directories and files? Can you use chown from the shell? Shared, dedicated, colo or self-hosted server?