Forum Moderators: coopster

Message Too Old, No Replies

Permissions and fwrite()

         

iceman22

5:44 am on Jan 5, 2005 (gmt 0)

10+ Year Member



At my old hosting I could freely use the open and write to files using fopen() and fwrite(), files created would be under the ownership of my username.

At my new hosting it's a little different, if I upload a file it'll be assigned to the ownership of my username, but if I create a file it will be under the ownership of 'nobody'. I get a permission denied error when I try to write to any file that is owned by my username.

This creates a problem as I can't edit any files created by nobody without changing the ownership. Last week all the files in my public_html directory changed ownership to my username, even if the owner was 'nobody'. This is a strange problem, it occured again today and the only solution I can find is to delete the files and let them be created again under the owner 'nobody'.

Because I am not the superuser I cannot change file ownership, why hey changed in the first place I am not sure, the support from my new hosting has been almost non existent, they claim the problem lies in my scripts. Even the error_log files have been changed to my username from 'nobody', so they haven't been updated since December 20.

Is there any way of authenticating a script to be able to modify files under my username?

I have suppressed the errors by putting an '@' in front of the file commands, is there any way of outputing a less obvious custom error?

Thanks a lot.

mincklerstraat

12:14 pm on Jan 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hey iceman,

Your username - let's pretend it's 'iceman' - is almost never the same (and really shouldn't be the same) as the name of the user that the Apache server is running under. In your case, Apache runs under the name 'nobody', quite a common setup. When you create files with scripts, these files are owned by the "user" who created them: that's the webserver, or "nobody". In general, you try to set things up so your webserver can only write to the files it needs to write to - otherwise anyone who succeeds in getting your webserver to run one of their scripts can change whatever files the webserver has permissions for.

This might be why those files changed ownership from 'nobody' to your username. It's possible your host runs some kind of script that checks for webserver-owned files, and switches them to your user name. However, I think it's more likely that somehow you, without knowing it, ftp'd these files back up. In that case, when you use ftp, the server sees these as 'your' files (your username, iceman).

What you can do to make files which iceman owns be writeable by the server is chmod them to 666. For directories, it's 777. Writeable by 'the world'. This comes, of course, with consequences for security.

iceman22

12:37 pm on Jan 5, 2005 (gmt 0)

10+ Year Member



Thanks for the reply. I think there could be a server cron script running because all the files were changed to the username, most of them were files never uploaded or touched with FTP. Perhaps GoLive made some changes but they're files I've never opened before.

I changed the permissions of the text file again, this time to 666, that fixed it.

Is there any other way to do this, because it would be good for a script to be able to create and add to the text file without having to change the permissions every time.

There are a lot of PHP error functions, is it possible to get the error so that I can output it the way I want?

Thanks.

mincklerstraat

4:17 pm on Jan 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Normally, changing permissions on a file is semi-permanent - the permissions stay that way unless the owner or root change the permissions to something else.

You can determine how errors are displayed by making your own custom error function - check out set_error_handler() for more info.