After some more research, I've got it figured out. Here is the solution for anyone having the same problem:
Since localhost belongs to the
Since localhost belongs to the
www-data
group, I just added my user to that group.sudo usermod -a -G www-data my_username
Then, I added the folder to the group.
sudo chgrp -R www-data /var/www
Then, I gave write permissions to the www-data group.
sudo chmod -R g+w /var/www
This worked for me without any other issue. Thanks!