Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't my PHP script chmod a file it creates?

Tags:

php

chmod

apache

I have a php that creates a file that needs to be executable (it's a batch file that needs to be run by the system). For some reason, even though the file is owned by apache and php is running as apache, and the file IS created, the script dies at the chmod line. What do I need to configure differently to allow the php to chmod the file it creates? Two lines above it happily creates a directory FOR this file which it chmods to 755 right as it creates it. Am I missing something obvious?

my chmod line looks like this:

    $uploadFilePath = "./path/to/file/";
    if(!is_dir($uploadFilePath)){
          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');
like image 630
Yevgeny Simkin Avatar asked Nov 05 '22 23:11

Yevgeny Simkin


1 Answers

Most probably due to umask. Try setting it to 0 prior to the chmod.

like image 149
mhitza Avatar answered Nov 10 '22 17:11

mhitza