777 is NOT correct on many servers. They will give a 500 error because this is a security exposure ("world writable files"). You start with the minimum permissions on any file (typically 644) and add "write" permissions (664, then 666) until you get it working. Very few servers now require PHP files to be marked "executable" (755, 775, 777). This applies to files that PHP needs to write to, and depends on how PHP is configured (especially, what user group it's running under).
777 was safe to do back in ancient times, when you could trust everyone sharing your Unix computer. You can't anymore, especially on a server shared with hundreds or even thousands of strangers. Giving them "world write" access to your files is asking for trouble. If someone blithely tells you to "chmod 777 your files", they're an idiot. Don't listen to them.