在linux中通过php创建文本文件

I am trying to create new text file through php by the following command:-

<?php
    $new = fopen('newfile.txt', 'w');
?>

Somehow it is unable to create it because of permissions issues of linux. Now I can only create text file first then set it's permissions. Or is there a way to do this in the code itself? Either way I need to get the job done.

You can create the directory and give it 744 permissions

$dir = 'output';

 if ( !file_exists($dir) ) {
     $mask = umask(0);  // helpful when used in linux server  
     mkdir ($dir, 0744);
 }

 file_put_contents ($dir.'/test.txt', 'Hello File');