Here is an explanation of each command you posted. Let me know if you have an specific questions.
User Groups
Replace Primary User Group of username
(from whatever it was set to before) to www-data
sudo usermod -g www-data username
Add a User Group called www-data
to any existing list of User Groups belonging to username
sudo usermod -aG www-data username
Note: In my tutorials, the “username” doesn’t need to be in multiple groups. Therefore I make “www-data” the primary. This practice can avoid issues in the future.
Change Owner (change owner > chown)
Change Owner of /var/www/html/mywebsite/
to username
and the Group to www-data
sudo chown username:www-data /var/www/html/mywebsite/
Change Owner of /var/www/html/mywebsite/
(including all sub-directories) to www-data
and the Group to www-data
sudo chown -R www-data:www-data /var/www/html/mywebsite/
Change Mode (change mode > chmod)
Change both the Directory and File permissions of /var/www/html/mywebsite/
(including all sub-directories) to mode 755 (i.e. User can read, write, and execute; group members and other users can read and execute, but cannot write)
sudo chmod -R 755 /var/www/html/mywebsite/