Frink a better solution and vastly more preferably is not widening the permissions but giving ownership of the files to the web/php user.
sudo chown www-data: <files>
www-data is default on a few systems
the owner can always write to the files it owns, whereas widening the permissions allows any script to modify files (also hacked sites)