0

I can't understand why a php function is_writable() returning always false. I see nothing in the log about it, and after searching for hours : I can't understand why.

File setup :

[root@localhost owncloud]# ls -la /etc/test
-rwxrwxrwx. 1 nginx nginx 4 Jul 31 17:41 /etc/test

test.php

<?php
    $filename = '/etc/test';
    echo exec('whoami');
    if (file_exists($filename)) {
        echo 'Exist';
    } else {
        echo 'NOT exist';
    }
    if (is_writable($filename)) {
        echo 'writable';
    } else {
        echo 'NOT writable';
    }
?>

it returns :

nginx
Exist
NOT writable 

My nginx has the following configuration :

/etc/nginx/nginx.conf

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log;
#error_log  /var/log/nginx/error.log  notice;
#error_log  /var/log/nginx/error.log  info;

pid        /run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;
    sendfile        on;
    keepalive_timeout  65;

   server {

    listen 8080 ssl;
    ssl_certificate     /etc/nginx/certs/owncloud.crt;
    ssl_certificate_key /etc/nginx/certs/owncloud.key;

    error_log /var/log/nginx/owncloud.log;
    access_log /var/log/nginx/owncloud.log;

    server_name owncloud;

    root /var/www/owncloud;

    client_max_body_size 10G; # set max upload size
    fastcgi_buffers 64 4K;

    rewrite ^/caldav(.*)$ /remote.php/caldav$1 redirect;
    rewrite ^/carddav(.*)$ /remote.php/carddav$1 redirect;
    rewrite ^/webdav(.*)$ /remote.php/webdav$1 redirect;

    index index.php;
    error_page 403 = /core/templates/403.php;
    error_page 404 = /core/templates/404.php;

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

    location ~ ^/(data|config|\.ht|db_structure\.xml|README) {
        #allow instead of deny for testing purpose    
            allow all;
    }

    location / {
            rewrite ^/.well-known/host-meta /public.php?service=host-meta last;
            rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json last;
            rewrite ^/.well-known/carddav /remote.php/carddav/ redirect;
            rewrite ^/.well-known/caldav /remote.php/caldav/ redirect;
            rewrite ^(/core/doc/[^\/]+/)$ $1/index.html;

            try_files $uri $uri/ index.php;
    }

    location ~ ^(.+?\.php)(/.*)?$ {
            try_files $1 = 404;

            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$1;
            fastcgi_param PATH_INFO $2;
            fastcgi_param HTTPS on;
            fastcgi_pass 127.0.0.1:9000;
    }
  }
}

/etc/php-fpm.conf

include=/etc/php-fpm.d/www.conf
[global]
pid = /run/php-fpm/php-fpm.pid
error_log = /var/log/php-fpm/error.log
log_level = debug
daemonize = no

/etc/php-fpm.d/www.conf

[www]
listen = 127.0.0.1:9000
listen.allowed_clients = 127.0.0.1
listen.owner = nginx 
listen.group = nginx
user = nginx
group = nginx
pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
slowlog = /var/log/php-fpm/www-slow.log
php_admin_value[error_log] = /var/log/php-fpm/www-error.log
php_admin_flag[log_errors] = on
php_value[session.save_handler] = files
php_value[session.save_path] = /var/lib/php/session
1
  • Does it work when you try another directory like /tmp rather than /etc/? If you delete the file, can PHP write it out? Try getting PHP to write the file and retrieve the permissions from what that does. Commented Jul 31, 2013 at 20:26

1 Answer 1

3

The problem was SELinux that seems to prevent nginx to write to some files. Disabling SELinux solve the problem

Not the answer you're looking for? Browse other questions tagged or ask your own question.