【问题标题】:Permission Denied on mkdir php with nginx使用 nginx 在 mkdir php 上拒绝权限
【发布时间】:2016-07-28 09:50:51
【问题描述】:

我正在努力解决 LEMP 堆栈上的问题。我无法让我的 nginx 用户通过 php 脚本创建目录。

我的堆栈是 RHEL 7.2 NGINX 玛丽亚分贝 PHP

我成功安装了堆栈并使用以下代码在 index.php 中创建目录

        <?php
           echo(exec("whoami"));
           mkdir("test",0777,true);
           $error=error_get_last();
           echo $error['mssage'];
        ?>

输出 nginx mkdir(): 权限被拒绝

Nginx 通过nginx 用户执行PHP

Applied 'chown -R nginx: nginx <working folder>'
Applied 'chmod -R 0777 <working folder>

但上面的脚本给出了相同的权限被拒绝错误。

我的计划是安装 Wordpress 并将网站导入此 Web 服务器。但由于 nginx 工作文件夹的权限被拒绝,Wordpress 无法创建新目录或将内容从一个文件夹移动到另一个文件夹。

【问题讨论】:

  • 所以一个原因可能是 SELinux 不允许 Nginx 写入目录,尽管这不太可能。要暂时检查此内容,请执行sudo su 以使您成为root 用户,然后运行echo 0 &gt; /selinux/enforce。再次尝试运行脚本。如果仍然出现相同的错误,请再次启用 SELinux echo 1 &gt; /selinux/enforce 并发布您尝试写入的目录结构的权限。

标签: php nginx mariadb rhel


【解决方案1】:

从 /etc/nginx 检查你的 nginx.conf 文件

并使用

获取 nginx 用户名
 sudo nano /etc/nginx/nginx.conf

例如,如果用户名是 www-data 然后使用

sudo chown -R www-data /home/www/ || /foldername/

然后转到你的文件目录

cd /home/www/

使用

检查 shell 中的权限
ls -l

现在检查你的开发中的mkdir()

【讨论】:

    【解决方案2】:

    在 /etc/selinux/config 中将 SELINUX 设置为禁用或允许

    如果 SELINUX 必须强制执行,请使用 semanage 更改 MySQL 数据目录及其内容的上下文。

    shell> 状态

    SELinux status: enabled
    SELinuxfs mount: /selinux
    Current mode: enforcing
    Mode from config file: enforcing
    Policy version: 24
    Policy from config file: targeted
    

    那么你就开启了 SELinux。

    其他可能的提示:

    http://forums.mysql.com/read.php?20,591661 (mysqld service won't start after server move)
    http://forums.mysql.com/read.php?20,568810 (MySQL LOAD DATA LOCAL INFILE)
    http://forums.mysql.com/read.php?52,275498 (Can't connect to MySQL server on '192.168.1.197' (13))
    http://forums.mysql.com/read.php?52,252406 (PHP Remote connection Issue)
    

    【讨论】:

      猜你喜欢
      • 2018-03-19
      • 1970-01-01
      • 2012-03-22
      • 1970-01-01
      • 2011-06-25
      • 2011-07-11
      • 2013-04-21
      • 2014-10-22
      • 2011-07-28
      相关资源
      最近更新 更多