php mkdir(): 权限被拒绝

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17450129/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 12:54:33  来源:igfitidea点击:

mkdir(): Permission denied

phpapacheyiipermissions

提问by awMinor

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

我的服务器上的所有文件都有 777 个。PHP 5.4(无安全模式)

Site works on other servers. It's Yii framework

站点在其他服务器上工作。这是 Yii 框架

 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 -lafter chown, not help

这里ls -l经过 chown,没有帮助

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

采纳答案by awMinor

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

检查 SELinux 并关闭它.. 现在它可以工作了!

回答by cb0

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)
  • web 目录归 apache 用户所有。(“ls -al”会告诉你)
  • 您要在其中创建的父目录也归该用户所有。
  • 父目录不是您没有写权限的挂载
  • 您要创建的路径是正确的(var_dump($dstDir) 会告诉您)
  • $this->newDirMode 包含正确的权限值。(如果您在 Windows 上运行,这将被忽略)

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)
  • 使自己成为 apache 用户并尝试手动创建它(“sudo -u apache”,如果您的用户名是 apache)
  • 尝试省略“mkdir($dstDir,$this->newDirMode,true);”中的第三个参数“true” 并一个接一个地创建所有目录
  • 检查日志(“/var/log/apache”是你的朋友)

Hope this helps.

希望这可以帮助。

回答by Keith Wagner

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

SELinux 可能是问题所在。尝试手动关闭它:

setenforce 0

回答by pawr

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

SELinux 是我设置的罪魁祸首。感谢您的提醒!