It's good practice to [not] use 777. This means that the file owner, other members of the group the owner belongs to, and all other users can read, write, and execute the file. In short, any and all users has unrestricted access to the file.
A quick summary of what these numbers mean:
The three numbers correlate to the different roles I mentioned. Owner, group, other users. There are two ways of setting file permissions. Using the three numbers is called octal notation. It uses binary to set the appropriate permissions for each role.
4 = read
2 = write
1 = execute
Add any of these to grant the permissions you wish. For example:
7 = 4+2+1, read, write, and execute (should be used for the owner)
6 = 4+2, read and write
5 = 4+1, read and execute
and so on and so forth. 0 means there is no access granted on any level to the role you've set.
Directories work differently, and this can also play a role in why your file might not be written to the directory. Ensure that the directory itself, not the files inside the directory, is set to allow being written to.
For more help, consult
guide from Linode
Edit: @8 is right, you don't need execute, and it's also a good practice to disable settings that you know won't be used. It's not hurting you to have it 755, but it does make more sense to have 644, just depends on your view.