The code file has the right to 777. What could be the problem?
Answer 1, Authority 100%
I can assume that the launch of applications does not happen on behalf of the user, but on behalf of the same Apache, but the “owner” of files filled to the server is already the user. I am not a big special in these issues, but google in this direction: “Starting applications on behalf of user ”
Answer 2, Authority 33%
Yes, most likely Apache (or that the web server works) is started under the user who has no rights to the file.
You can try apache to run under a different user, or to give the user to File.