The reason for 0777 instead of 777 is because the leading zero causes it to be interpreted as octal instead of decimal, which is what you want. Continue using 0777.
You have two different problems here. First, when you use mkdir, the permissions are modified by umask. You probably want to mkdir the directory, then chmod it to what you really want. The other way to do it is to set umask to permissive, mkdir, then restore umask.
Second, the chmod on the file is failing because the filename is wrong. You have a leading slash on the chmod, but not on the mkdir. That makes a difference.