I'm running a local nginx server with php to write a piece of code which basically has an upload functionality. I need to upload images to a folder tmp
and then work on. But I guess there are some issues with the folder permissions coz php is sending back an error UPLOAD_ERR_CANT_WRITE
.
ls -l
in the directory:
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. It should not. Look in config for "Group".
Easy way is
ps aux|grep php
look php daemon user and chown tmp folder to that user.
remember php usually not run by same user as nginx, they are different processes
Although the Group Permission is set to www-data
the User is looks to still be assigned to yourself. 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.
=> php-fpm needs write access, not nginx. php-fpm process running as uid 1000, not as www-data
so you could 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.