Sign up ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

I am running Ubuntu on my vserver and I have set up quite a few settings concerning my topic. But I am not really sure if it is set up correctly.

My current setup is the following:


export APACHE_RUN_USER=www-data
export APACHE_RUN_GROUP=www-data
export APACHE_PID_FILE=/var/run/

I read articles about adding an extra user e.g. sudo adduser apache which runs the apache server, so whats a good choice?

Website Directories:

drwxr-xr-x 5 www-data:www-data 4.0K Feb  5 04:16 mysite/

This directory for example is placed in /var/www. My folder settings inside the dir are chmod 755 and my files are 644. Should it be owned by www-data or by my username?

Id be glad if you can give me some best practices on this. Thx for advise!

share|improve this question
To accomplish what goal? One website? Multiple sites? Hosting your clients? Multiple developers? One developer? If you can modify the question to include a basic scenario and strategy... someone might be able to help. – user8290 Feb 11 '12 at 23:13

1 Answer 1

The biggest thing I've learned is to not give Apache write access to anything you do not need to write too, for example cache, user, or download directories that you can upload stuff to.

So take ownership of everything with something like sudo chown user:user on the website directory and give the o other bit the permissions needed... .

Replace user:user with a user and group you would like.

On the directories you can use a command like:

sudo chmod o+rx /var/www/'directory' #make directory read and executable for other
sudo chmod o-wx /var/www/'directory'/'files' #remove write and execute from files
sudo chmod o+r  /var/www/'directory'/'files' #add read to files

You can also use a find command that is a little advanced but makes the job a little easier, something like (after having owned the files with):

chown user:user /var/www/ -R # this is only an example.. 
  • directories
find /var/www/ -type d -exec sudo chmod o+rx {} \; 
  • files
find /var/www/ -type f -exec sudo chmod o-wx {} \;
find /var/www/ -type f -exec sudo chmod o+r {} \;

I tried to be as descriptive as possible. I can explain more if needed. This talks about permissions about half way down:

share|improve this answer

Your Answer


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.