[英]File Upload Permissions error in Nginx, PHP
I'm running a local nginx server with php to write a piece of code which basically has an upload functionality. 我正在用php运行本地nginx服务器,以编写一段基本上具有上传功能的代码。 I need to upload images to a folder
tmp
and then work on. 我需要将图像上传到
tmp
文件夹,然后继续工作。 But I guess there are some issues with the folder permissions coz php is sending back an error UPLOAD_ERR_CANT_WRITE
. 但我想文件夹权限coz php会发回错误
UPLOAD_ERR_CANT_WRITE
出现一些问题。
ls -l
in the directory: ls -l
在目录中:
drwxr-xr-x 2 root root 4096 Mar 22 19:20 assets
-rw-r--r-- 1 root root 1564 Mar 22 19:20 cropper.php
drwxr-xr-x 5 root root 4096 Mar 22 19:20 files
drwxr-xr-x 2 root root 4096 Mar 22 19:20 images
-rw-r--r-- 1 root root 10018 Mar 22 19:20 index.htm
-rw-r--r-- 1 root root 7972 Mar 22 19:20 second-page.php
drwxrwxr-x 2 arjun www-data 4096 Mar 22 19:20 tmp
i tried to change permissions around but they keep on failing. 我试图更改权限,但它们继续失败。 So how do I get out of this mess?
那么我如何摆脱这种混乱呢?
be sure php runs as www-data group. 确保php作为www-data组运行。 It should not.
它不应该。 Look in config for "Group".
在配置中查找“组”。
Easy way is 简单的方法是
ps aux|grep php ps aux | grep php
look php daemon user and chown tmp folder to that user. 看看php守护程序用户和该用户的chown tmp文件夹。
remember php usually not run by same user as nginx, they are different processes 记住,php通常不是由与nginx相同的用户运行,它们是不同的进程
Although the Group Permission is set to www-data
the User is looks to still be assigned to yourself. 尽管“组权限”设置为
www-data
但看起来用户仍会分配给您自己。 If you cd
to the directory and run chown -Rf www-data:www-data
it will set the owner of the tmp
directory to the web server, and should then allow php to write to that folder. 如果您
cd
到目录并运行chown -Rf www-data:www-data
,它将把tmp
目录的所有者设置为Web服务器,然后应允许php写入该文件夹。
=> php-fpm needs write access, not nginx. => php-fpm需要写访问权限,而不是nginx。 php-fpm process running as uid 1000, not as www-data
php-fpm进程以uid 1000而不是www-data的身份运行
so you could chgrp -R 1000 tmp 所以你可以chgrp -R 1000 tmp
ideally you would limit what directory www-data and php-fpm have write access to, Likewise limit it to an upload directory for example in WordPress. 理想情况下,您将限制对www-data和php-fpm的目录具有写访问权限,同样,将其限制为例如WordPress中的上载目录。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.