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 changed ownership of my localhost file on /var/www/ and its sub folders and given it permission 777. However, whenever I add a new folder in it the new folder does not automatically get that permission. How can I give a folder 777 permission forever so that if I add a new folder or file it gets the same permission?

share|improve this question
4  
PLEASE read this Reasons why /var/www SHOULD NOT have chmod 777 –  Marco Ceppi Jan 20 '11 at 12:26
    
The 777 is a bad idea. But using ACL could fit very well. Will you please read this solution on ACL to see if it works well for you? –  user8290 Jan 20 '11 at 15:51
1  
Relatedly, to chmod all directories you can use find . -type d -exec chmod 777 {} + to change all directories to 777. Remember, you must be logged in as root for better results, and make sure you are in the folder. –  Ida Bagus Redy Santiawan Aug 14 '12 at 5:58
    

6 Answers 6

up vote 1 down vote accepted

Permissions for newly created files are set by umask

share|improve this answer
    
can u write the command for making /var/www/ writable and giving it permission such that i get same permission (777) for site i recently add in it. –  kamal Jan 20 '11 at 9:39
1  
Giving 777 permission to your webserver is not good. –  saji89 Aug 13 '12 at 4:07
    
Could you please add more details. –  saji89 Aug 13 '12 at 6:13
    
@ Vojtech Trefny. The link is not working at the moment.It says 404 Not Found. –  all4naija Aug 15 '12 at 18:40

As others have already mentioned, giving 777 permissions on /var/www is a really bad idea, especially in production.

A better solution would be to give write permissions only to the users who needs to modify the files. One of the ways to do that is:

  • create a new group

  • add the user(s) who needs to modify the data in /var/www to that group

  • recursively change the ownership of /var/www to that group

  • set umask on /var/www so all newly created files are owned by the group we've created.

Another option would be to use ACL, again, to give write permissions only to users who need them.

Here are detailed instructions on serverfault.

Generally, the webserver or other network services or system user accounts should have no write permissions to the files served by the webserver, as this opens a possibility of arbitrary code execution.

share|improve this answer

You should edit /etc/apache/envvars as root with your editor of choice.

Example: ALT+F2
gksudo gedit /etc/apache2/envvars

Go to the end of the file and add a line umask XXX.

Where umask is the binary opposite of the desired permissions value.
For 774 this would be 003. For 777 bad idea it would be 000.

Save.

Restart apache.

Example: sudo apache2ctl restart

This will only affect files/folders that are newly created by the apache user.

Additional note, read and write is 6 in the user, group, or anyone slot.

share|improve this answer

I think you want to have write access to /var/www to modify files and dirs. I think the best solution is to install apache2-mpm-itk and in the virtual host config file add /etc/apache2/sites-available/default:

<IfModule mpm_itk_module>
    AssignUserId your-username your-group
</IfModule>

and run chown your-username\: /var/www -Rv this way apache for that virtual host will run with your UID/GID and you will be able to edit files. Even files created by PHP will have your UID/GID

share|improve this answer

Also, some "out of the box" solution is to configure your http server to use different folder. If You use Apache, simply edit it config files. This way You do not have to change permissions for /var/www witch can be bad idea (potential security issues).

And umask is answer for Your question. It can be used to restrict default privileges for newly created folders and files. And distribution developers tend to use it to restrict access to some system folders.

share|improve this answer

You can use the recursive option any time. sudo chown -R username /var/www

share|improve this answer
    
You need more upvotes! –  Sheharyar Mar 31 at 16:07

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.