Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5986497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:40:47+00:00 2026-05-22T22:40:47+00:00

I can’t understand why I have to use chmod to get the correct permissions..

  • 0

I can’t understand why I have to use chmod to get the correct permissions..
The file is created succesfully but with 0755 and not 0775 that I specify in mkdir .

( http://php.net/manual/en/function.mkdir.php )

I have to do chmod after mkdir to set the correct permissions.

Safe mode is off in php.ini and the folder belongs to php’s group and owner (www-data)

This doesn’t work:

  if(!is_dir("/var/www/customers/$username/$project_name")) 
  {
    mkdir("/var/www/customers/$username/$project_name",0775);

  }

But this does:

  if(!is_dir("/var/www/customers/$username/$project_name")) 
  {
    mkdir("/var/www/customers/$username/$project_name");
    chmod("/var/www/customers/$username/$project_name",0775);

  }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T22:40:48+00:00Added an answer on May 22, 2026 at 10:40 pm

    Yes, it’s because of umask…

    from comments of docs: http://php.net/manual/en/function.mkdir.php

    You might notice that when you create
    a new directory using this code:

    mkdir($dir, 0777);

    The created folder actually has
    permissions of 0755, instead of the
    specified
    0777. Why is this you ask? Because of umask(): http://php.net/manual/en/function.umask.php

    The default value of umask, at least
    on my setup, is 18. Which is 22 octal,
    or
    0022. This means that when you use mkdir() to CHMOD the created folder to
    0777, PHP takes 0777 and substracts
    the current value of umask, in our
    case 0022, so the result is 0755 –
    which is not what you wanted,
    probably.

    The “fix” for this is simple, include
    this line:

    $old_umask = umask(0);

    Right before creating a folder with
    mkdir() to have the actual value you
    put be used as the CHMOD. If you would
    like to return umask to its original
    value when you’re done, use this:

    umask($old_umask);

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
I have just tried to save a simple *.rtf file with some websites and
Can someone guide me on a possible solution? I don't want to use /bin/cp
Can you guys help me understand a concept real quick, I'm having trouble understanding
Can't figure out how to do this in a pretty way : I have
I want use html5's new tag to play a wav file (currently only supported
Can you have submenus with the top level set to checkable in WPF? I
Can we use the asterisk character * for a search action in SQL database?
Can't seem to get the Back Button to appear in a UINavigationController flow. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.