Community Forums
Connect with us on LinkedIn
+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Member
    Join Date
    May 2003
    Posts
    16

    Default PHP can not create dirs with chmod 755

    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
    Geraldo Ramos
    www.gigahost.com.br

  2. #2
    Technical Product Specialist cPanelDavidG's Avatar
    Join Date
    Nov 2006
    Location
    Houston, TX
    Posts
    11,189
    cPanel/Enkompass Access Level

    Root Administrator

    Default

    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. #3
    Member
    Join Date
    May 2003
    Posts
    16

    Default

    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&#180;t the new dir have chmod 750? If so, why do they fave 744?
    Last edited by geraldo; 10-17-2007 at 05:51 PM.
    Geraldo Ramos
    www.gigahost.com.br

  4. #4
    Technical Product Specialist cPanelDavidG's Avatar
    Join Date
    Nov 2006
    Location
    Houston, TX
    Posts
    11,189
    cPanel/Enkompass Access Level

    Root Administrator

    Default

    Quote Originally Posted by geraldo View Post
    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&#180;t the new dir have chmod 750? If so, why do they fave 744?
    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.
    Last edited by cPanelDavidG; 10-18-2007 at 09:17 AM. Reason: Attempting to avoid debates about binary arithmetic.

Similar Threads & Tags
Similar threads

  1. Cpanel folder chmod 755
    By beau in forum cPanel and WHM Discussions
    Replies: 3
    Last Post: 06-16-2008, 09:52 AM
  2. Unable to CHMOD a dir back to 755
    By Xiode in forum cPanel and WHM Discussions
    Replies: 7
    Last Post: 07-17-2007, 04:21 AM
  3. Password protect dirs + symlink dirs
    By abronier in forum cPanel and WHM Discussions
    Replies: 0
    Last Post: 07-15-2007, 07:00 AM
  4. chmod 644 for files and 755 for directories
    By CoolMike in forum cPanel and WHM Discussions
    Replies: 1
    Last Post: 11-05-2005, 04:24 AM
  5. A way to chmod public_html's to 755 in one hit via ssh?
    By pingo in forum cPanel and WHM Discussions
    Replies: 5
    Last Post: 12-12-2003, 10:12 AM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube