Linux – How to administer /var/www

apache-http-serverdocumentslinuxpermissionswww

I'm new to Linux and I'm trying to setup a small testing server inside of a VM running Ubuntu Server. I've found the /var/www folder and it should be the one where my Apache documents are stored, in fact if I access my VM's IP I see the index.html page that's stored there.

My problem is that I can't write to that folder.

ls -l returns:

d-w-r-xr-x 2  root root 4096 2011-12-28 16:08 ./ 
drwxr-xr-x 13 root root 4096 2011-12-28 17:02 ../ 
-rw-r--r-- 1  root root 177  2011-12-28 16:08 index.html

My user is called gab.

What's the best thing to do when dealing with this folder to allow myself to edit and create files here? Should I create a new group or set myself as the owner of the folder?

Best Answer

That is a protected folder. You need to be root in order to modify this directory.

You can also make gab the owner of this directory by doing

sudo chown -R gab /var/www

sudo will execute the chown -R gab /var/www command as a root (administrator) and prompt you for your password used when setting up the system (most likely the same password as gab).

Once you do this, you can also do

sudo chown -R 755 /var/www

to give write permissions.

#   Permission
7   full
6   read and write
5   read and execute
4   read only
3   write and execute
2   write only
1   execute only
0   none


Reference   Class   Description
u   user    the owner of the file
g   group   users who are members of the file's group
o   others  users who are not the owner of the file or members of the group

The 755 means that the user will have full access, group will have read and execute access and others will have read and execute access.

Related Question