Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wrong permissions set on newly created directory

This is the code that creates the "cache" folder with the wrong permissions:

mkdir($saveFolder, 02775);

When I inspect the folder permissions, using ls -la, I receive:

drwxr-sr-x

But instead I'm expecting:

drwxrwsr-x
like image 255
siannone Avatar asked Sep 22 '15 12:09

siannone


2 Answers

For some obscure reasons (at least for me) changing the code to

mkdir($saveFolder);
chmod($saveFolder, 02775);

solved the issue.

Now I get the right permissions set on the folder:

drwxrwsr-x
like image 113
siannone Avatar answered Sep 23 '22 04:09

siannone


Your current umask also affects the mode so depending on your umask settings, the mode of the created directory may not match the octal specified in your function call. http://php.net/manual/en/function.mkdir.php:

The mode is 0777 by default, which means the widest possible access. For more information on modes, read the details on the chmod() page. Note that you probably want to specify the mode as an octal number, which means it should have a leading zero. The mode is also modified by the current umask, which you can change using umask().

Try setting umask(0) and the argument supplied to mkdir() should work as expected.

More discussion here: https://bugs.php.net/bug.php?id=65796

like image 38
Eaten by a Grue Avatar answered Sep 25 '22 04:09

Eaten by a Grue