fix_www-data
##Fix www-data permissions
usermod -aG www-data myUser
chown -R myUser:www-data /var/www
chmod 2775 /var/www
2 → set group id
7 → rwx for owner (myUser)
7 → rwx for group (www-data)
5 → rx for world
Set group ID (SETGID) bit (2) causes the group (www-data) to be copied to all new files/folders created in that folder.
There's a -R recursive option, but that won't discriminate between files and folders, so you have to use find, like so :
find /var/www -type d -exec chmod 2775 {} +
Change all the files to 0664
find /var/www -type f -exec chmod 0664 {} +