6

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?

3 Answers 3

9

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.

5

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]
2
  • 2
    To me anything that does not need executing should be set to 644 and not 0755 ;)
    – Rinzwind
    Oct 30, 2012 at 11:07
  • For me it was enough to have read right and own the file to upload.
    – Timo
    Aug 31, 2020 at 17:28
1

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

You must log in to answer this question.

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