Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

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

I have a php file which is trying to read and write xml files on my Ubuntu server, however the problem is that it does not have permission to do this (permission denied error).

I have tried the following chown www-data read_write.php with no luck

What is the proper way to change permission for this file?

more info

-rwxrwxr-x 1 www-data www-data 14092 Sep 6 12:33 read_write.php

share|improve this question
up vote 4 down vote accepted

The script must be allowed to write in the directory in which it tries to create the files. So for example, if the script tries to write a file into the directory /var/srv/www/script_output/, do

chown www-data:www-data /var/srv/www/script_output/
chmod 771 /var/srv/www/script_output

Make sure that you do not give permissions for writing in the directory that the script resides in (otherwise, an attacker hijacking the script would be able to overwrite the script itself). Also, files in that directory should not be permitted to be run (as PHP or whatever).

By the way, the d in drwxrwxr-x only means that the given node is a directory.

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.