mkdir(): Permission denied

23,668

Solution 1

Check SELinux and turn off it.. Now it works!

Solution 2

Make sure that:

  • the web directory is owned by the apache user. ("ls -al" will tell you)
  • the parent directory in which you want to create is also owned by this user.
  • the parent directory isn't a mount in which you don't have write permissions
  • the path you want to create is correct (var_dump($dstDir) will tell you)
  • $this->newDirMode is contains a correct permission value. (If you are running on windows this will be ignored)

If there is no problem and it still doesn't work I would do:

  • make yourself the apache user and try to create it manually ("sudo -u apache" if your username is apache)
  • try to omit the third parameter 'true' in "mkdir($dstDir,$this->newDirMode,true);" and create all directories one after another
  • inspect the logs ("/var/log/apache" is your friend)

Hope this helps.

Solution 3

SELinux may be the problem. Try turning it off manually:

setenforce 0

Solution 4

SELinux was the culprit for my set up. Thanks for the reminder!

Share:
23,668

Related videos on Youtube

awMinor
Author by

awMinor

Web developer, works on PHP/Javascript. In free time try learn java and run servers

Updated on December 03, 2020

Comments

  • awMinor
    awMinor over 3 years

    I have 777 on all files on my server. PHP 5.4 (no safe_mode)

    Site works on other servers. It's Yii framework

     mkdir(): Permission denied
    
    /var/www/html/project/framework/web/CAssetManager.php(225)
    
    213             return $this->_published[$path];
    214         elseif(($src=realpath($path))!==false)
    215         {
    216             $dir=$this->generatePath($src,$hashByName);
    217             $dstDir=$this->getBasePath().DIRECTORY_SEPARATOR.$dir;
    218             if(is_file($src))
    219             {
    220                 $fileName=basename($src);
    221                 $dstFile=$dstDir.DIRECTORY_SEPARATOR.$fileName;
    222 
    223                 if(!is_dir($dstDir))
    224                 {
    225                     mkdir($dstDir,$this->newDirMode,true);
    226                     chmod($dstDir,$this->newDirMode);
    227                 }
    

    Here ls -l after chown, not help

    drwsrwsrwx.  2 apache apache    4096 июля   3 16:44 assets
    drwxrwxrwx.  5 apache apache    4096 июня  10 14:52 bootstrap
    drwxrwxrwx. 19 apache apache    4096 июля   3 16:04 framework
    -rwxrwxrwx.  1 apache apache     326 июля   3 16:42 index.php
    drwxrwxrwx. 10 apache apache    4096 июля   3 16:04 protected
    drwxrwxrwx.  3 apache apache    4096 июня  20 13:28 soap
    drwxrwxrwx.  3 apache apache    4096 июля   3 16:04 themes
    
    • eric.itzhak
      eric.itzhak almost 11 years
      You need 777 on the dir you're trying to make a dir in as well, or change it's owner.
    • Cobra_Fast
      Cobra_Fast almost 11 years
      You should also use octal representation for file and directory permissions. 0777 instead of 777.
    • awMinor
      awMinor almost 11 years
      It's Yii framework. I can't change this code.. All /www/ have 777
    • Anigel
      Anigel almost 11 years
      I have seen this fail before even with 777 if the directory owner is not the webserver user that is running the script. change the directories so they are owned by the web server user (apache, nobody or www-data etc depending on your server) and this will normally solve your problem. Another cause is the drive being full
    • Chris Hanson
      Chris Hanson almost 11 years
      Can you show us the results of ls -la in the parent directory (and that directory's parent)?
    • awMinor
      awMinor almost 11 years
      add some info... This not help...
    • Amal Murali
      Amal Murali almost 11 years
      @user2546911: do ls -la on your parent directory and post the output here, as @ChrisHanson told you.
    • Chris Hanson
      Chris Hanson almost 11 years
      If @cb0 answer doesn't get there, provide the result of var_dump($dstDir).
    • awMinor
      awMinor almost 11 years
      All parents have apache owner
  • cb0
    cb0 almost 11 years
    What user is defined in your /etc/apache2/apache2.conf ? (Search for 'User' followed by 'Group')
  • awMinor
    awMinor almost 11 years
    I think, SELinux.. Other domain is work in /var/www/html/, but i haven't any info in SELinux
  • cb0
    cb0 almost 11 years
    Your 'ls -la' shows me that this should be ok :( Does creating the directory manually worked ?
  • Steven V
    Steven V almost 11 years
    This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient reputation you will be able to comment on any post.
  • Brant Olsen
    Brant Olsen almost 11 years
    Please use the edit link on your question to add additional information. The Post Answer button should be used only for complete answers to the question.
  • pawr
    pawr over 9 years
    Permissions and ownership was also an issue. My solution: chown -R apache basic/
  • pawr
    pawr over 9 years
    chgrp -R apache basic/
  • pawr
    pawr over 9 years
    chmod 755 permissions for your webroot recursively as well got mine working followed by the 'setenforce 0' and the always helpful 'service httpd restart' just in case =) thank you everyone for your help on this one. Looking forward to playing with Yii 2.0