I've got a php that produces personal files that should be executable (it is a batch file that should be run through the system). For whatever reason, despite the fact that the file is possessed by apache and php is running as apache, and also the file IS produced, the script dies in the chmod line. What should i configure in a different way to permit the php to chmod the file it produces? Two lines above it happily produces a directory With this file so it chmods to 755 right because it produces it. Shall We Be Held missing something apparent?

my chmod line appears like this:

    $uploadFilePath = "./path/to/file/";
          mkdir($uploadFilePath, 0777 , true) or die("ERROR:can't create directory '$uploadFilePath'");
    //write batch file
    chmod ($uploadFilePath . 'sftp.batch' ,0777 ) or die ("\ncan't chmod  " . $uploadFilePath . 'sftp.batch');

Most most likely because of umask. Try setting it to 0 just before the chmod.