Allow PHP to write file without 777

I am setting up a simple website on webspace provided by my university. I do not have database access so I am storing all the data in a flat file. The issue I am experiencing is related to file permissions. I need PHP to be able to read and write the data file but I don't really want to set the file to 777 as anybody else on the system could modify it, they already have read access to everyone's web directories. Does anyone have any ideas on how to accomplish this?

Thanks in advance


Just set 0755 (or lower) but make sure that directory owner is user in which context is apache (or other webserver) running.

for example

chown apache:apache /var/www/html

You can get info about user using phpinfo() for example.

UPDATE

If you are sharing apache with more sites, then you should separate your content by Per-user web directories

http://httpd.apache.org/docs/2.2/howto/public_html.html


You may use suPHP to accomplish this task. If you can use it, then simply change the file permissions to 0700 and everything shall work as you want.


The ideal situation would be if the filesystem on the server supports posix acls so you can add write access to certain files for the uid the webserver runs under.

And you have enough access to the filesystem (preferably via a shell account) to set acl rights.

See man acl for an overview and man setfacl for details on how to set them.