*nix-style services and permissions on NTFS filesystems

2008-03-16 23:09 by Ian

What follows is a ticket that I had last night. It sums up the problems that *nix users often have when trying to understand permissions on Windows servers. This not only applies to PHP, but to any *nix service that runs on Windows and needs to deal with file permissions. This includes FTP, PHP and Ruby (not hosted here for a reason).

Hello Again,
I just can't seem to get any of the files in my php library to work right on Crystal Tech servers. I have a file (http://***.***.***.***/edit/create.php) that triggers another php file (http://***.***.***.***/edit/create_x.php) to make a directory and copy a couple of files into it. The script creates the directory, although it doesn't set the permissions as I specified in the script, but does not copy the files into the directory.

Any help would be appreciated. I have these files on a few other servers and they run without problems but this is the first time I've worked with an NT server so I am not familiar with any conflicts between the hosting environment and PHP.

Thank You, *****

A couple questions...
What directory gets created and where?
What line of what file sets the permissions?

Microsoft's permissions scheme is a train wreck. The standard chmod style permissions do not work in windows. It will ignore calls that attempt to set file permissions using this convention.

Ian Lindsay
Technical Support Technician

Hell Again,
Okie Dokie, I'll try to explain the two files as best I can, they're not very difficult. In the first file (http://***.***.***.***/edit/create.php) you type something in a form field and hit the submit button. This posts the contents of that form field to the second file (http://***.***.***.***/edit/create_x.php) and makes a folder named whatever you typed in the form field, the line that creates the directory is...

mkdir("$itemno", 0666);

...where "$itemno" is the variable from the form field. As you can see permissions are declared aside of it, but sometimes this doesn't work right on an Apache server which is why the permissions are set again with a chmod command on the next line...

chmod("$itemno", 0666);

Originally I had these set to "0755" but I had changed them back to "0666" because it seems that your servers change the permissions back to that setting anyway.

Please bear with me here, there is a good chance that I'll be working on a number of sites on Crystal Tech servers and it will be important for me to understand better how your machines are set up.

Thank You, *****

Yeah... the problem isn't your code. The problem is the fact that Windows will ignore those permissions entirely. When Windows reports the permissions as 0666, it is arbitrary. The return value is in no way connected to the *actual* permissions.

If you are pulling your hair in frustration, you would not be the first.

I've never had to use PHP to create directories on an NTFS filesystem, but the strategy below should work...

Use the control center's file permissions tool to set the permissions for the EVERYONE user to READ / WRITE / EXEC / DEL for the directory in which your new directories will be created. Make sure to propagate the permissions to all sub files and folders.

In other words, if you wanted to create the directory "new_dir" you would have to do it in a folder that EVERYONE has R/W/E/D permissions to.

This way when PHP creates something new under that directory, it *should* inherrit the same permissions. You can remove the chmod command from your code. It will not do anything.

Ian Lindsay
Technical Support Technician

Hello Again,
Thanks Ian,
Worked like a charm.

Thank You, *****