test.sh's path is /var/www/proj/test.sh, and project.php is inside /var/www/ and my test.sh uses and creates some .txt files.

when i execute test.sh 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/test.sh: line 8: /var/www/project/result/List.txt: Permission denied

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

  • Is your project.php file calling the test.sh? Or what is the relationship between these files? – Ale Apr 21 '13 at 20:44
  • yeah...project.php calls test.sh 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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