简体   繁体   English

使用 nginx 在 mkdir php 上被拒绝权限

[英]Permission Denied on mkdir php with nginx

I am struggling with an issue on LEMP stack.我正在努力解决 LEMP 堆栈的问题。 I cannot make my nginx user to create directory via php script.我无法让我的 nginx 用户通过 php 脚本创建目录。

My stack is RHEL 7.2 NGINX MariadB PHP我的堆栈是 RHEL 7.2 NGINX MariadB PHP

I installed the stack successfully and used following code for creating directory in index.php我成功安装了堆栈并使用以下代码在 index.php 中创建目录

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

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

Nginx excecutes PHP via nginx user. Nginx 通过nginx用户执行PHP

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

But above script gives same permission denied error.但上面的脚本给出了相同的权限被拒绝错误。

My plan is to install Wordpress and import sites to this web server.我的计划是安装 Wordpress 并将站点导入到此 Web 服务器。 But since permission is denied on working folder of nginx , Wordpress is not able to create new directories or move content from one folder to other.但是由于 nginx 的工作文件夹的权限被拒绝,Wordpress 无法创建新目录或将内容从一个文件夹移动到另一个文件夹。

Set SELINUX to disabled or permissive in /etc/selinux/config在 /etc/selinux/config 中将 SELINUX 设置为禁用或允许

If SELINUX has to be Enforcing, use semanage to change the context of the MySQL datadir and its contents.如果 SELINUX 必须是 Enforcing,请使用 semanage 更改 MySQL 数据目录及其内容的上下文。

shell> sestatus外壳> 状态

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

then you have SELinux on.那么你就拥有了 SELinux。

Other possible tips:其他可能的提示:

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)

check your nginx.conf file from /etc/nginx从 /etc/nginx 检查你的 nginx.conf 文件

and get the nginx username using并使用获取 nginx 用户名

 sudo nano /etc/nginx/nginx.conf

For example if the username is www-data then use例如,如果用户名是 www-data 然后使用

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

then go to your file directory然后转到您的文件目录

cd /home/www/

check the permissions in shell using使用检查shell中的权限

ls -l

Now check the mkdir() in your development现在检查开发中的mkdir()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM