2

My website is running on nginx + php-fpm and running well but while uploading file it shows blank page.My log file shows

2016/06/08 14:44:40 [error] 22063#22063: *25 FastCGI sent in stderr: "PHP message: PHP Warning:  file_put_contents(up/propic/medium/5961465411480.jpg): failed to open stream: Permission denied in /var/www/example.com/saveimg.php on line 32" while reading response header from upstream, client:...

I tried most of answers from stackoverflow , even I changed the /var/www folder permissions to 777 but the results are same.

Few details about my server

/etc/php-fpm.d

 user=nginx
 group=nginx

ownership and group of /var/www/sites

drwxrwxrwx. 29 ec2-user root 4096 Jun  8 14:39 site1.com
Raj
  • 159
  • 1
  • 1
  • 11
  • What is the parameter of "file_put_contents" function resolves to? Looks like it is *something*/up/propic/medium/5961465411480.jpg so you need to check permissions of every single folder on the way to *something*/up/propic/medium/5961465411480.jpg – amaksr Jun 08 '16 at 19:44
  • Possible duplicate of [Failed to open stream : No such file or directory](http://stackoverflow.com/questions/36577020/failed-to-open-stream-no-such-file-or-directory) – Vic Seedoubleyew Jun 12 '16 at 09:44

4 Answers4

12

After searching , I found it.It's all deals with SELINUX which is a security feature. when using ls -Z

drwxrwxrwx. ec2-user root system_u:object_r:httpd_sys_content_t:s0 www

change this to

drwxrwxrwx. ec2-user root system_u:object_r:httpd_sys_rw_content_t:s0 www

using cmd

chcon -R -t httpd_sys_rw_content_t /var/www
Raj
  • 159
  • 1
  • 1
  • 11
0

You also need to check permissions and ownership of every folder on the way from

/var/www/sites/

to

/var/www/sites/site1.com/up/propic/medium
amaksr
  • 7,555
  • 2
  • 16
  • 17
0

The user and group defined in your pool.d configuration require access rights to your nginx root location. This can be done by changing the user and group in your pool.d configuration to the same user and group that own your nginx root location or by adding the pool.d user to the group that owns your nginx root location. You can do that like this:

usermod -a -G groupName userName
Lonkey
  • 183
  • 10
0
# nginx error.log echo:
2019/10/12 11:11:02 [error] 3871#0: *1 FastCGI sent in stderr: "PHP message: PHP Warning:  Unknown: failed to open stream: Permission denied in Unknown on line 0
Unable to open primary script: /www/test.php (Permission denied)" while reading response header from upstream, client: 192.168.1.9, server: _, request: "GET /test.php HTTP/1.1", upstream: "fastcgi://unix:/run/php-fpm/www.sock:", host: "192.168.1.180"

In Centos System, After searching , I found it.It's all deals with SELINUX which is a security feature. when using ls -alZ

drwxrwxrwx. ec2-user root system_u:object_r:httpd_sys_content_t:s0 www
# change this to
drwxrwxrwx. ec2-user root system_u:object_r:httpd_sys_rw_content_t:s0 www

# using cmd
chcon -R -t httpd_sys_rw_content_t /www
asins
  • 11
  • 3