First, you should ensure that your username is included in www-data
group. If not, you can add your username as www-data
group
sudo adduser yourusername www-data
yourusername can be changed with your username.
After that, you should change the ownership of /var/www to your username
chown -R user:www-data /var/www && find /var/www -type f -exec chmod 0660 {} \; && find /var/www -type d -exec chmod 0770 {} \;