here's my suggestion:
$ sudo chown www-data:www-data -R /var/www
(changes the permissions to be owned by www-data). I'm not sure why it defaults to root anyways.
$ sudo gpasswd -a $USER www-data (add yourself to the www-data group)
$ sudo chmod g+rw -R /var/www #make all files write by group owner.
$ sudo find -type d -exec chmod g+rwx {} \; #find folders and make sure group has rwx access.
logout, log back in.
you should now be able to write any files as yourself.
You could simply chown /var/www to your $USER, though I wouldn't recommend it. partly because it's insecure, and partly because I think some things will probably break if you do.
chown -R root:$USER /var/www
? If it is unsecure, why? – Esamo Dec 19 '13 at 05:02sudo gpasswd -a $USER www-data
? We want to add the user to thewww-data
group, not the other way around. – kaerimasu Dec 28 '17 at 15:09