<p>How can you allow a PHP script to write to a file with high-security restrictions, such as only allowing a single user to write to it?</p>

<p>The difficulty seems to be that a PHP script is running as a low-permissions user (maybe apache, or www, or nobody?), and even if I <code>chown</code> apache the_writable_file, the directory it's in might not be writable for the low-level user.  In general, what's the usual way that PHP can work with local files in a secure way?</p>

Sure,
```
chgrp apache the_writable_file
```
and
```
chmod g+w the_writable_file
```
.  After that, only your secure user and the apache user will be able to write to the file.  Since the apache user is typically forbidden from logging in, you only have to worry about web users writing to your secure file using through the http daemon.