ssh2_sftp_mkdir($sftp, '/home/site',0774);
I am using the above to create a folder remotely but instead of the folder having permissions 774
it is getting set as 754
meaning that it is not writeable by the group.
ssh2_sftp_mkdir($sftp, '/home/site',0774);
I am using the above to create a folder remotely but instead of the folder having permissions 774
it is getting set as 754
meaning that it is not writeable by the group.
The mode is also modified by the current umask, which you can change using umask().
What's happening is that php function ssh2_sftp_mkdir
is for some reason affected by system umask
settings, and the problem is this isn't documented.
For example, if you do
ssh2_sftp_mkdir($sftp, '/home/site',0774);
and umask
on your system is set to 022
(as it is default on most Linux distributions), you will end up with created directory site
that has permissions 754
(drwxr-xr--
)
It is possible to alter umask
from php by using function umask, but as noted in the documentation, it's not recommended because of posibillity of unexpected behavior in multithreaded webservers.
For understanding what is umask
and how it works for example in Debian Linux, please refer to Debian Wiki - Permissions - The defaults for new files and directories, or Arch Linux Wiki - Umask.
My advice for handling this situation is to make best effort for setting up permissions when creating directory / file, and after creating, make sure to set proper permissions using ssh2_sftp_chmod
function.
In this case, that would be
/* Create directory */
ssh2_sftp_mkdir($sftp, '/home/site',0774);
/* Make sure proper permissions are set */
ssh2_sftp_chmod($sftp, '/home/site',0774);