My user can't upload files to folders owned by www-data

I think I have screwed up my permissions in Ubuntu.

I am using my server to run PHP. I recently ran across a problem where PHP could not create directories in the var/www-directory, so I searched around on the internet. Now PHP can write and access anything like it should, but as a user, I can't create new folders or files anymore.

Right now, the permissions for folders are like this:

drwxrwsr-x 2 www-data www-data [Folders]

This is the permissions when I upload using sftp:

-rw-rw-r-- 1 gautvedt www-data [Folders]

What have I done wrong and how can I change this?


You need to include yourself into the www-data group.

Graphical method

Command line:

sudo adduser gautvedt www-data

That way you can add things to directories where www-data owns the group.


There are more methods but this is the easiest one.


After add user to www-data group as mentioned by Rinzwind, you should change the permission to 755

sudo chmod 0755 -R /var/www

without changing permission, it can't be accessed (forbidden). So, it will change to

drwxr-xr-x 1 gautvedt www-data [Folders]

On Ubuntu 14.04 (at least) you can use...

gpasswd -a username www-data

this will add the www-data group to the existing user account