allow access to www-data to files in user's home dir

I have 2 users with the following home directories:

  • user1 --> /srv/user1
  • user2 --> /srv/user2

Problem is: I want these home folders to be accessible online via apache2 but accessible to the users as well . If I set the owner of each home directory to the corresponding user, I can ftp to these directories, but apache fails to access the files. If I set owner to www-data, the directories work fine with apache, but the users can't read their own home directories.

If I add user1 and user2 to www-data group and give +rw to the entire group, this will make user 1 able to read user 2's files (and vice-versa), and I want each user to read his own files only.

How can I achieve this?

Thanks in advance


I think what you want is the other way round. Provide the www-data account access to the user files:

usermod -a -G users www-data