Jump to content

Permission denied to make directory


NotionCommotion

Recommended Posts

I am sure it is a silly mistake, but don't see it.  Can anyone tell me why I cannot create a directory?  Thanks

echo('filepath1: '.$filepath1.'<br>');
echo('filepath2: '.$filepath2.'<br>');
echo('fileowner: '.posix_getpwuid(fileowner($filepath1))['name'].'<br>');
echo('fileperms: '.substr(sprintf('%o', fileperms($filepath1)), -4).'<br>');
echo('current_user: '.get_current_user().'<br>');
echo('filepath1 exists: '.(file_exists($filepath1)?'Yes':'No').'<br>');
echo('filepath1 is a directory: '.(is_dir($filepath1)?'Yes':'No').'<br>');
echo('filepath2 exists: '.(file_exists($filepath2)?'Yes':'No').'<br>');
if(!file_exists($filepath2)){mkdir($filepath2, 0755);}
filepath1: /var/www/main/user_resources/documents/30
filepath2: /var/www/main/user_resources/documents/30/01
fileowner: NotionCommotion
fileperms: 0755
current_user: NotionCommotion
filepath1 exists: Yes
filepath1 is a directory: Yes
filepath2 exists: No
An error occurred in script '/var/www/main/
application/classes/application.php' on line 197: mkdir(): Permission denied (error no: 2). [12.34.56.789]

 

Link to comment
Share on other sites

@NotionCommotion: Your code checks the permissions of the script owner, but you need to know the UID of the process:

var_dump( posix_getuid() );

That most definitely isn't “NotionCommotion”, rather something like “www-data”.

 

If you want PHP to create directories, you need to make www-data (or whatever the user is called) the owner of the parent directory.

Edited by Jacques1
Link to comment
Share on other sites

Well, I feel silly.  PHP is being ran as apache.  Probably better to use something like www-data so it is simpler to change websevers if desired.

 

Still odd that I earlier wasn't able to create the directory.  I changed permissions to 0775, and apache belonged to the NotionCommotion group.  Oh well, all is good now, and probably best not to use groups like I did for this.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.