Results 1 to 10 of 16

Thread: Allow a user write access to /var/www - what's the best approach

Hybrid View

  1. #1
    Join Date
    Sep 2008
    Location
    Michigan, USA
    Beans
    193
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: Allow a user write access to /var/www - what's the best approach

    I agree with crazycaveman as well...

    Make sure the group is www-data on '/var/www'.

    prompt> sudo chgrp www-data /var/www

    Make '/var/www' writable for the group.

    prompt> sudo chmod 775 /var/www

    Set the GID for www-data for all sub-folders.

    prompt> sudo chmod g+s /var/www

    Your directory should look like this on an 'ls -l' output.

    drwxrwsr-x

    Last, add your user name to the www-data group (secondary group).

    prompt> sudo useradd -G www-data [USERNAME]

    You should now be able to SFTP to your server as your user name and upload to '/var/www' with no problems.

  2. #2
    Join Date
    May 2008
    Location
    Birmingham, UK
    Beans
    283
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: Allow a user write access to /var/www - what's the best approach

    An alternative is simply to move the default Apache site elsewhere - see https://help.ubuntu.com/community/Ap...irtual%20Hosts

  3. #3
    Join Date
    Jan 2007
    Location
    netherlands
    Beans
    19
    Distro
    Ubuntu 8.04 Hardy Heron

    Smile Re: Allow a user write access to /var/www - what's the best approach

    Thanks all for your kind, prompt and clear answers. I followed Killahurtz's instructions and got the following:

    Code:
    Last login: Mon Sep 15 00:15:57 2008 from 192.168.0.50
    arnan@motoko:/var$ sudo chgrp www-data /var/www
    [sudo] password for arnan: ********************
    arnan@motoko:/var$ sudo chmod 775 /var/www
    arnan@motoko:/var$ sudo chmod g+s /var/www
    arnan@motoko:/var$ sudo useradd -G www-data arnan
    useradd: user arnan exists
    arnan@motoko:/var$ 
    
    arnan@motoko:/var$ ls -lt
    total 40
    drwxr-xr-x  2 root root     4096 2008-09-15 06:28 backups
    drwxr-xr-x 10 root root     4096 2008-09-15 06:28 log
    drwxr-xr-x 10 root root      380 2008-09-15 01:04 run
    drwxr-xr-x 25 root root     4096 2008-09-15 00:54 lib
    drwxrwxrwt  3 root root       60 2008-09-14 03:12 lock
    drwxrwsr-x  2 root www-data 4096 2008-09-13 18:37 www
    drwxr-xr-x  8 root root     4096 2008-09-13 18:37 cache
    drwxr-xr-x  3 root root     4096 2008-09-13 18:37 spool
    drwxrwsr-x  2 root mail     4096 2008-09-13 18:32 mail
    drwxr-xr-x  2 root root     4096 2008-09-13 18:32 opt
    drwxrwsr-x  2 root staff    4096 2008-06-13 16:14 local
    drwxrwxrwt  2 root root     4096 2008-06-13 16:14 tmp
    I then logged in with my user 'arnan' via SFTP and tried to upload a file to the /var/www but i still got the permission denied thing.

    I'm guessing folder ownership should remain root? Or should i change that too?

    Thanks!

  4. #4
    Join Date
    Jan 2007
    Location
    netherlands
    Beans
    19
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: Allow a user write access to /var/www - what's the best approach

    Just tried :

    Code:
    sudo chown arnan /var/www
    which seems to work fine, apache still reads the thing and i can view the "site". the "IT WORKS!" thing...

    THanks again for all your help guys!

  5. #5
    Join Date
    Sep 2006
    Location
    Daly City, CA
    Beans
    39
    Distro
    Ubuntu

    Lightbulb Re: Allow a user write access to /var/www - what's the best approach

    Quote Originally Posted by SHRIKEE View Post
    Just tried :

    Code:
    sudo chown arnan /var/www
    which seems to work fine
    Sorry to resurrect this thread, but I found it via Google...

    Anyway, the "proper" way of adding an existing user to a group is to use
    Code:
    sudo usermod -a -G {group} {username}
    I'm adding this just in case someone else finds it useful.
    Running some form of Ubuntu on really questionable hardware since 2006.

  6. #6
    Join Date
    Nov 2004
    Location
    Kuala Lumpur, Malaysia
    Beans
    885
    Distro
    Xubuntu 14.04 Trusty Tahr

    Re: Allow a user write access to /var/www - what's the best approach

    Another method that I like to use is to enable the userdir mod.

    Code:
    sudo a2enmod userdir
    All the user needs to do is save his PHP/HTML files in -> /home/<<username>>/public_html

    Browse it at URL -> http://localhost/~username/

    For example if my username is john, I need to save my web files in /home/john/public_html and to browse it just point my webbrowser to http://localhost/~john/

    This way, each web developer has his/her own folder. Less chance of messing things up. Only when a site or project is ready to go live, then only I'll migrate it to the proper /var/www/
    Last edited by Buffalo Soldier; December 8th, 2008 at 02:29 AM.

  7. #7
    Join Date
    Oct 2009
    Beans
    2

    Re: Allow a user write access to /var/www - what's the best approach

    Quote Originally Posted by Buffalo Soldier View Post
    Another method that I like to use is to enable the userdir mod.
    ....
    Thanks so much! this approach is exactly what i was looking for. cheers.

  8. #8
    Join Date
    Dec 2008
    Beans
    9

    Re: Allow a user write access to /var/www - what's the best approach

    Quote Originally Posted by ocdude View Post
    Sorry to resurrect this thread, but I found it via Google...

    Anyway, the "proper" way of adding an existing user to a group is to use
    Code:
    sudo usermod -a -G {group} {username}
    I'm adding this just in case someone else finds it useful.
    Exactly what did it. Thank you!

  9. #9
    Join Date
    Jul 2008
    Beans
    83

    Re: Allow a user write access to /var/www - what's the best approach

    This worked perfectly for me, thanks !

    Quote Originally Posted by KiLaHuRtZ View Post
    I agree with crazycaveman as well...

    Make sure the group is www-data on '/var/www'.

    prompt> sudo chgrp www-data /var/www

    Make '/var/www' writable for the group.

    prompt> sudo chmod 775 /var/www

    Set the GID for www-data for all sub-folders.

    prompt> sudo chmod g+s /var/www

    Your directory should look like this on an 'ls -l' output.

    drwxrwsr-x

    Last, add your user name to the www-data group (secondary group).

    prompt> sudo useradd -G www-data [USERNAME]

    You should now be able to SFTP to your server as your user name and upload to '/var/www' with no problems.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •