I`ll explain about correct file permissions for www. First find what user and group apache is using. Www files should have owner is user who edit the files, and group from apache. Permissions should be "rw" for user, "r" for group, and folders should also have X permission. For folders used by php to write something add "w" permission for group.
Find user name used by apache:
ps -aux|grep apache You`ll see something like www-data
Change ownership to you and group:
sudo chown -R yourusername:www-data /var/www
chmod -R u=rwX,g=rX,o= /var/www
Add write access for scripts to certain folders, what used as cache or similar:
chmod -R g+w /var/www/html/templates_cache
Do it for each folder what in need for write access.