First of all, you can see the permission of /var/www has, by this command ls -l /var/www. You will see like this (this only for example):
drwxr--r-- 7 www-data www-data 4096 Jun 21 10:53 CodeIgniter
drwxr--r-- 11 www-data www-data 4096 Oct 2 19:49 eAdministration
drwxr-sr-x is permission status and www-data www-data is ownership status. By default, when you installed for first time, ownership status is www-data www-data. The thing that you should do, add your username belongs to www-data group by this command:
sudo adduser yourusername www-data
After that, you should change the ownership to your username:
sudo chown yourusername:www-data -R /var/www
It will result in:
drwxr--r-- 7 yourusername www-data 4096 Jun 21 10:53 CodeIgniter
drwxr--r-- 11 yourusername www-data 4096 Oct 2 19:49 eAdministration
Then, you should change permission to 755 (rwxr-xr-x) for directories, 644 (rw-r--r--) for files, and I do not recommend to change permission to 777 (rwxrwxrwx). As suggestion from temoto to make easier to be understand, you can do this:
sudo find /var/www -type d -print0 | sudo xargs -0 chmod u=rwX,go=rX
sudo find /var/www -type d -print0 | sudo xargs -0 chmod u=rw,go=r
OR
sudo find /var/www -type d -print0 | sudo xargs -0 chmod 0755
sudo find /var/www -type f -print0 | sudo xargs -0 chmod 0644
To ensure that setting has been running well, you can try php code in /var/www.
Xpermission asxfor directories and empty for files. It's possible to runfind /var/www -print0 |xargs -0 chmod u=rwX,go=rX. With added benefit of easier to understand permissions. – temoto Feb 09 '16 at 13:33/var/www/htmlI can not docat > test.txteven with sudo! (I used last options ofsudo find etcalso) – Peter Krauss Feb 13 '17 at 20:34groups <username>– metamorph Feb 14 '17 at 01:12sudo find /var/www -type d -print0 | sudo xargs -0 chmod u=rw,go=r, which will list directories (-type d) instead of files (-type f). – AntonK Jun 01 '18 at 23:20