For some reason when I upload to my website, Apache saves the file as user
www-data and group
www-data, rather than user
myusername and group
How do I fix this?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
Apache does saves files as www-data, because it is the user it runs with for security reasons.
What you can do is create a specific user and group for your site, and use mod-ruid2 to configure your vhost to use that user.
For installing it:
sudo apt-get install libapache2-mod-ruid2
And for configuring it in the vhost:
<Directory "/var/www/mydir"> RMode config RUidGid my_new_user my_new_group
Each vhost can also have different users, which in multi vhost servers can be convenient, either for multi-host configurations with multiple users, or for knowing whether vhost is sending spam, for instance.
As for the ownership of files, read on.
In the directory of your vhost, you also configure it with setuid or SetGid directory, for any file that you leave there as your normal user that also belongs to that group, to be forced to that group or user and not your normal group.
For forcing user ownership, follow the next steps:
chown my_new_user.my_new_group /var/www/mydir
setUID for directory
chmod u+s /var/www/mydir
setGID for directory
chmod u+g /var/www/mydir