How can I set chmod 777 for my lamp server?

I am the owner of the www folder (sudo chown -R martin www). I have changed the permissions of all files (sudo chmod 777 -R www).

I don't know why, but my website is working only with chmod 777. Otherwise I see only white page.

I'm working with .tpl files (include file="header.tpl", but when I use a new file , it will be not shown until I make chmod 777 for that file).

How can I set chmod 777 permanently for all new files in this folder?

  • 1
    777 is (almost) always a bad idea!
    – guntbert
    May 14, 2013 at 19:28

1 Answer 1


Actually you should never ever make web root writable. See Why should /var/www not have chmod 777?

I suspect what you really want to do is to set the directories to 755 and, either leave the files alone, or set them to 644. For this you can use the find command e.g.

To change all the directories to 755:

find /var/www -type d -exec chmod 755 {} \;

To change all the files to 644:

find /var/www -type f -exec chmod 644 {} \;

Also, to give permissions for files to be seen in browser, use:

chown -R www-data:www-data /var/www/

If your www directory is not in /var, change /var/www with the right way.

Update: Any new files copied to the folder /var/www would not have your custom set permissions. You would need to run the command again to set the permissions for new files too.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .