Super User is a question and answer site for computer enthusiasts and power users. 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's path is /var/www/proj/, and project.php is inside /var/www/ and my uses and creates some .txt files.

when i execute through terminal it works fine, but when I run project.php by


it fails, the permissions on the txt files also changed, so I have to manually change the permissions of the txt file, even to run through terminal again.


rm: remove write-protected regular empty file `/var/www/project/result/List.txt'?  
project/ line 8: /var/www/project/result/List.txt: Permission denied

So, how can I permanently give write access to /var/www/*

share|improve this question
Is your project.php file calling the Or what is the relationship between these files? – Ale Apr 21 '13 at 20:44
yeah...project.php calls whenever the page is refreshed – pali Apr 21 '13 at 20:47

To give write access to /var/www you need to give write access to the user who runs the web server. On Ubuntu for example this can generally be done with:

chown www-data /var/www
chmod u+w /var/www

(to set www-data, being the user running the web server, as owner of /var/www and giving write access to the directory to its owner -- in case he doesn't already have). Depending on your server's configuration, in some cases this might not work (e.g., blocked by a SELinux or AppArmor policy).

However, for security reasons it is not advisable to do this. In the worst case (given a bug in one of the scripts running on the web server), an external attacker might write arbitrary data to /var/www, either putting any contents on your web server, or scripts that he can then execute...

Depending on your application, you might give access to the web server to another (dedicated) directory, and retrieve the files from that directory when you need them in a PHP script.

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.