Googlers, do not use composer with sudo:
Add your user in the www-data group (this action require you to logout and login again)
sudo usermod -a -G www-data `whoami`
Give the right permissions to /var/www
sudo chown root:root /var/www
sudo chmod 755 /var/www/
Give these permissions to your project
sudo chown -R www-data:www-data /var/www/<project>
sudo chmod -R 774 /var/www/<project>