Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question

3 Answers 3

up vote 4 down vote accepted

That is a protected folder. You will need to be sudo in order to access 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 super user (adminsitrator) 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.

share|improve this answer
    
If you're worried about someone else having access to the server, you can always just sudo whenever you need to copy files to that directory. –  kobaltz Dec 28 '11 at 19:09
    
oh, and the -R is used as a recursive, making the directory and it's contents owned by and permissions set to. –  kobaltz Dec 28 '11 at 19:10

I was going to suggest you become a member of the www-data (or equivalent) group, but since the directory and the index.html file are both owned by root, you may indeed be expected to do so (as kobaltz suggested)—if you want to avoid Virtual Hosts.
If you go the way of Virtual Hosts, the /var/www directory is merely a placeholder that allows you to verify that Apache is running.

I know it's a bit of a read, but did you have a look at this documentation page or this wiki page?

share|improve this answer

Actually the files should be owned by www-data (or www-data should have write privileges). The 'lazy' way is to use sudo to switch yourself to root and chown the files to yourself, do what you need to do, then switch it back to www-data - i think these files were added using sudo, but whoever did it did not give ownership over to www-data

The right way is to set the folder to be group writable, and to add yourself to said group. This of course makes more sense since you only have to do it once (for the www-data directory), and you can work with your regular user after that. Kobaltz has the right basic idea, but some aspects of execution seem incorrect to me.

share|improve this answer

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.