Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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
add comment

1 Answer

up vote 3 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
add comment

Your Answer

 
discard

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.