I'm going to fore go temtation to evaluate your code, and suggest, given the error coode
HTTP 500. That this has more to do with
permissions, than the code itself. In other words; it appears that your script, or the files that it attempts to access, do NOT have permission to either READ, or WRITE, or EXECUTE, under the ownership of the user that the scripts are owned. see
chmod,
chown, for hints to this. As well as the Web Server software, that manages the scripts/files.
Best wishes
--Chris
¡λɐp ʇɑəɹ⅁ ɐ əʌɐɥ puɐ ʻꜱdləɥ ꜱᴉɥʇ ədoH