Bug 1045778

Summary: php fails to recognize write permission if run via a web server (nginx + php-fpm)
Product: [Fedora] Fedora Reporter: Máté Wierdl <wierdlmate>
Component: phpAssignee: Joe Orton <jorton>
Status: CLOSED NOTABUG QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: high Docs Contact:
Priority: unspecified    
Version: 19CC: fedora, jorton, rpm, wierdlmate
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2013-12-23 18:44:04 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Attachments:
Description Flags
test write permission via php none

Description Máté Wierdl 2013-12-21 23:12:17 UTC
Created attachment 840188 [details]
test write permission via php

Description of problem: php doesn't recognize write permission of a file.  This happens only when it's run via a webserver (nginx).  This is why I am assuming, the bug is in the php-fpm package.


Version-Release number of selected component (if applicable):

$ rpm -q nginx php-fpm php
nginx-1.4.4-1.fc19.x86_64
php-fpm-5.5.7-1.fc19.x86_64
php-5.5.7-1.fc19.x86_64

How reproducible:
always

Steps to Reproduce:
1. You need to have php, nginx (or probably any other web server set up to run php-fpm)

2) cd to a directory which is serverd by the webserver.

$ cd /usr/share/nginx/html/wd369.memphis.edu

3) Create the attached php file (prolly you have to be root)

$ cat test_wperm.php
<?php
define('MYBB_ROOT', dirname(__FILE__)."/");

$configwritable = @fopen(MYBB_ROOT.'try.txt', 'w');

if(!$configwritable)
  {
    echo "not writable";
  }
else
  {
    echo "writable";
  }
@fclose($configwritable);

?>


4)    Create the writable file try.txt

$ touch try.txt && chmod 666 try.txt


5) Run the test program through php

# php -f test_wperm.php 
writable

6) Now open test_wperm.php in your browser via the webserver.  In my case

http://wd369.memphis.edu/test_wperm.php

I get the output in my browser

not writable

Additional remarks: 

1) I noticed the bug when trying to install the Simple Machines and the Mybb forum softwares.  For me the bug is serious since these programs failed to install because of this problem while on my ubuntu box, they install fine. 

2) My  nginx config for php-fpm is 

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
            root           html;
            #try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;   
            fastcgi_pass   127.0.0.1:9000;
            #fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/html/wd369.memphis.
edu$fastcgi_script_name;
            include        fastcgi_params;
        }

Comment 1 Máté Wierdl 2013-12-22 03:04:41 UTC
Unfortunately, nginx might also be at fault: on my ubuntu box, I have an older version, 1.4.1.  Recall, that this version works fine with php.

Comment 2 Remi Collet 2013-12-23 13:40:28 UTC
Please check SElinux context.

With SELinux ON, you need to set writable file context to httpd_sys_rw_content_t.

Comment 3 Máté Wierdl 2013-12-23 18:44:04 UTC
 That's exactly what the problem was.  Thanks.