As many have already said, don't ever, ever use the rights 777. You just asking for your site to be hacked.
Look into which user and group your webserver runns ass, www-data I think is the answer, you have to check.
Then change the user and/or group of files and directories you need access to.
See man pages for chown and chgrp.