in reply to system call to pdflatex

Does your script actually run as the user apache?

Does the user as which the script runs really have the appropriate permissions? Is something like AppArmor or SELinux active?

You don't check the result of system - you should do that to be able to stop the process and generate an error message for the user.