Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How do I grant a PHP script access to read and write log files in the /var/log/ and /var/ directories?

share|improve this question

I'd like to point out that giving write access to /var/log/ is a bad idea. Write access to /var/log/ means that an attacker can overwrite any of your logs, making it impossible to track down an attack on your server. If you wish to log from PHP, either make a single directory just for your php script's log (say, /var/log/php/) and give write access to it, or use syslog() and related functions to write to the standard system logs.

For read access, you'll need to determine what is creating the log files and make sure they're created with permissions that allow the user PHP is running as to read them. You can change them manually, but next time logs are rotated and new log files are created, you will probably have to change them again.

share|improve this answer

Find out which user php is running as and chmod the files/directories to match.

Quick and dirty way to find out:

share|improve this answer

One of the most straight-forward ways to do this is to ensure that the user who is running the PHP script has the required access. You can use chmod to modify permissions and chown/chgrp to change ownerships as necessary.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.