views:

86

answers:

2

Hi,

I want my PHP software to be able to auto update. For this to work, I need PHP to be able to write into files both existing and non-existing (create). Will it always work if I just CHMOD the target files to be 0777 and then write into it? Or does the PHP/Apache/wtvr process need to be the owner of the file?

Sometimes when people upload using an FTP account, the owner might be different from the PHP process, is this a problem?

Edit: I'm building a PHP application, I can't know on which configurations the app will run on, and I can't modify any server related settings. I can do what PHP can do, like chown(), chmod().

+1  A: 

Make the folder that you want to upload into owned by your www server. Then your php script will be able to write into that folder if it's chmodded 755.

# chown www somefolder
# chmod 755 !$

(Don't make other stuff in your web files owned by www).

Gazzer
Is there a way to find out the www user via PHP?
rFactor
Make a folder chmod 777, and then make a small php script to write a file in that folder then ls -l and see the owner of the file, I guess. There are easier ways though. Do you have root access?
Gazzer
+2  A: 

I have one server where, when files are uploaded through FTP, the ownership of the file changes to the ftp user which has caused a few permission problems in the past.

We use groups to get round this

For example, you could create a usergroup for accessing the files and add apache plus each of your ftp users to the group:

usermod -a -G appUpdaters www
usermod -a -G appUpdaters ftp1
usermod -a -G appUpdaters ftp2
etc...

Then you can chown the file/folders to a user + group and chmod to 775

chown www.appUpdaters foldername
chmod 775 foldername

That way if the ownership changes to ftp1.appUpdaters or ftp2.appUpdaters, the other users can still write to the file.

Like I say, I don't seem to need this on all the servers I use so I guess whether you do or not depends on your server config. If you do decide to use groups tho, I find this link comes in handy sometimes

http://www.cyberciti.biz/faq/howto-linux-add-user-to-group/

Addsy
I think there's a problem. I don't think I can create user groups via PHP? Don't I need an access to the server? I'm just a developer, writing software for multiple platforms.
rFactor