The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

PHP can not create dirs with chmod 755

Discussion in 'General Discussion' started by geraldo, Oct 8, 2007.

  1. geraldo

    geraldo Member

    Joined:
    May 1, 2003
    Messages:
    16
    Likes Received:
    0
    Trophy Points:
    1
    Hello,
    I have a server running php 5.2.4 with CGI as Server API and suexec, but scripts cant create dirs in php with chmod 755. When I use mkdir("/home/user/public_html/$dirname", 0755); it creates the dir with chmod 744. Why?

    I can change later this chmod to 755 in php with the chmod function. But why my server doesnt allow the directory to be created as 755? Where can I configure it?

    Let me clarify my problem:

    Script 1 (Should create a dir with chmod 755. But creates it with chmod 744.):
    <?
    //some code
    mkdir("/home/user/public_html/$dirname", 0755); //Create with chmod 744 ;/ That´s not what I want
    ?>

    Script 2 (Works fine):
    <?
    //some code
    mkdir("/home/user/public_html/$dirname", 0755); // Creates with 744 ;/ That´s not what I want
    chmod ("/home/user/public_html/$dirname", 0755); // Correct this weird bug
    ?>

    Script 3 (works fine also):
    <?php
    //some code
    umask(0022);
    mkdir("/home/linuxsvr/public_html/$dirname", 0755); //Create with chmod 755 ;D
    ?>


    m1k33
     
  2. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    This documentation may be useful: http://us.php.net/umask

    Especially this warning in the documentation:
    Using umask() can lead to unexpected behavior of concurrently running scripts and the webserver itself because they all use the same umask.
     
  3. geraldo

    geraldo Member

    Joined:
    May 1, 2003
    Messages:
    16
    Likes Received:
    0
    Trophy Points:
    1
    Thanks. When I tried it in php (<? echo umask(); ?> i received 27. Should I change it to 0022 as default? Where can I change it?

    By the way, if it is 27, if I understood it correctly, shouldn´t the new dir have chmod 750? If so, why do they fave 744?
     
    #3 geraldo, Oct 17, 2007
    Last edited: Oct 17, 2007
  4. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Keep in mind umask in PHP is not directly subtraction (a common misunderstanding), it's a bit operation. One of the user-supplied comments (timestamped: 20-Sep-2002 12:04) on that page explains this very well.

    As stated in the documentation, the parameter you pass to umask is what you are setting the mask to.
     
    #4 cPanelDavidG, Oct 18, 2007
    Last edited: Oct 18, 2007
Loading...

Share This Page