6

I'm a web developer, and so have set-up an old machine in the office as an Ubuntu Server, for the purposes of testing websites.

I've set-up LAMP and have created a /var/www folder, from which all my local sites are served. The issue is that of user permissions, i.e. any files that I copy into that folder (from my Windows machine via the network) automatically take on me (daniel) as their owner. The problem is that I want www-data to become the owner.

I did some research and saw that it should be possible to use setuid (and setgid) to automatically set www-data as the owner of all files put into /var/www automatically, so far I've not had any luck making it work.

Can someone help please? Thank you

UPDATE: Would this do what I want it to do? Default file permissions for php user www-data

UPDATE 2: I've kinda fixed my issue by changing my samba settings. Using Webmin, I was able to go in and change the default settings (as seen here: http://imageshack.us/photo/my-images/521/captureon.png/)

4 Answers 4

4

This was fixed by the user by setting the following file permissions using Webmin:

  • New Unix file mode: 664
  • New Unix directory mode: 775
  • Force Unix user: www-data
  • Force Unix group: www-data
  • Allow symlinks outside share?: Yes [questionable]
  • Can delete readonly files?: No
  • Force Unix file mode: 000
  • Force Unix directory mode: 000

See:

enter image description here

2

You can fire up a terminal and type:

sudo chown -R www-data /var/www

The -R stands for recursive for every file and directory under /var/www and www-data will be the owner.

1
  • 3
    Thank you for your answer, but that isn't what I want. I'm trying to avoid the need to chown each time I add a new file - I want some type of mask that will automatically set the owner as www-data :) Nov 16, 2011 at 13:12
0

first add your user to the www-data group.

sudo usermod -a -G www-data your_user

You can then make www-data your group, temporarily

newgrp www-data

This starts a new shell. any new file you create will be owned by www-data.

You then make /var/www owned and rw by root.www-data

sudo chown -R root:www-data /var/www

On a "production server" I will keep files owned by root, and, as much as possible, ro by www-data , but this may not be practical.

You can make www-data your primary group with usermod

sudo usermod -g www-data your_user
0

Linux systems ignore the setuid permission flag, but you can apply the setgid flag for each directory within /var/www:

find /var/www -type d -exec chmod g+s {} +

This will make each new file inherit the group of the directory while the user retains ownership, e.g. daniel:www-data.

But, if you absolutely need the files to have a certain owner, you could set up a cron job to fix it on a regular interval.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .