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/apache2.pid

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!

  • 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

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:


  • Descriptive! The answer I was looking for! – evilReiko Dec 4 '18 at 7:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.