Hey guys. I have just moved my site to a new server. On the old server I used mkdir() and it worked just fine, it created the folder and set permissions to 777, which is what I need.

The new server, however, creates the folder but the permissions are 755 even though I have 0777 as the permission setting in the mkdir() function.

To top it off, I can't even manualy go in and change the permissions on the folder because it says I don't have permission.

Now, my question is, is the because Safe Mode is on? I am not sure safe mode was turned on on the old server (older version of php), but I know it is on this one.

We have a dedicated server, would it be ok to turn safe mode off? If not, what would be a good work around for this problem?

Thanks guys!

    Safe mode is okay to turn off. In fact, it's so okay to turn off, that in PHP5 it's off by default, and in PHP 6 they're removing it 😉

    There really isn't a work around for safe-mode. You just have to have it on or off. But if your code is secure, then you've got nothing to worry about. If your code is full of security holes, safe-mode can help.

    I would have to venture a guess that safe-mode is creating these issues. But there's only one way to find out: try it.

      Thanks for the response. I had safe mode turned off and it is still doing the same thing.

      Any idea why mkdir() won't create a folder with 777 permissions?

      thanks!

        a month later

        any resolution to this yet? im having the same issue

          Will your server(s) allow 0777 permissions? Some won't let you do it. Will 755 work?

            Try using chmod() after you do the mkdir(). (mkdir() will be affected by the umask of the directory in which you are creating the new directory, and the umask() manual page recommends you use chmod() rather than trying to modify the umask within your PHP script.)

              11 days later

              If safe mode is enabled, mkdir() is useless.

              This is simply always the case. Safe mode itself is of limited usefulness and will be removed in PHP6.

              If you can convince your sysadmin to use base_opendir and disable_functions in lieu of safe mode, you should do so.

              To approximately emulate safe mode's restrictions, they should:

              disable_functions = dl,exec,passthru,system,shell_exec,popen
              open_basedir = ... whatever, as necessary
              

              This is not necessarily exhaustive though.

              Mark

                Write a Reply...