sudo su
Assuming you have su permission, if not all the following commands should be prepended with sudo
add yourself to the server users group
adduser user:www-data (could be another user group)
Change ownership of all files in the document root to ensure server can manage them
chown www-data:www-data -R /path/to/directory
As a side note the chown can be run with your-user:www-data which would mean you own the files but the webserver can still access them. (you will definitely want umask if you do this, otherwise you may be changing ownership and permissions frequently as the web server will own the files it creates).
make all files read and write including the directory (possible security implications with chmod and -R recursive flag so use it cautiously)
chmod g+rw -R /path/to/directory
Now if the files are created by the webserver itself they usually only have write access to the owner and read to the group. To resolve that matter you will need to look into umask as mentioned above and get directions as to where to set the umask and the correct setting your for your specific application.
For apache 2 (ive used nano as i find it the easiest editor in terminal).
nano /etc/apache2/envvars
add to end of file: umask 002
save the file.
service apache2 restart
This was found here: https://stackoverflow.com/questions/428416/setting-the-umask-of-the-apache-user and should probably be the accepted answer submitted by patrick fisher