开发者

PHP and CHMOD question

开发者 https://www.devze.com 2022-12-15 09:48 出处:网络
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 fi

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 n开发者_如何学Goeed 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().


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/


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消