To give user mywebsite
read/write permission inside /var/www/html/mywebsite
:
chown -R mywebsite /var/www/html/mywebsite
That should be sufficient. You should not have to alter group owner or permissions because the user owner should be given read/write permissions already.
If you wanted to grant a group read/write permission inside that folder, say, group my-group
, you'd need:
chgrp -R my-group /var/www/html/mywebsite
chmod -R g+w /var/www/html/mywebsite
Important notes
Don't set the ownership (either user or group) of files within /var/www
to the www-data
user. The point of having the web server run as the www-data
user is that this is an unprivileged account, unable to modify any files. If you set some files to be owned by this user, you are negating that security measure. If you need your web server to be able to modify certain files, only set ownership for those particular files and be very careful not to allow direct execution (eg via PHP) of them. In general, never set it so that www-data
can modify files.
When doing a recursive chmod
, it is often better to use letters than numbers, eg chmod -R g+w something
rather than chmod -R 770 something
. This is because the former is able to modify only the permission you want, and leave the others. By default, directories and files will have different "execute" permissions - files will have it off (eg 644) and directories on (eg 755) because this permissions has a different meaning for directories. If you do chmod -R 770 something
then regular files will have execute permissions turned on. In general it's a good idea to only modify what you need.
Another thing to note is that 770
would remove the world-readable permission, which will prevent the web server (which runs as an unprivileged user) being able to read it. In this case it's also preventing the user mywebsite
being able to see the /var/www/html/mywebsite
directory at all, because you've set the parent directory /var/www/html
to 770.