我不明白为什么 php 函数 is_writable() 返回总是假的。我在日志中什么也没看到,搜索了几个小时后:我不明白为什么。
文件设置:
[root@localhost owncloud]# ls -la /etc/test
-rwxrwxrwx. 1 nginx nginx 4 Jul 31 17:41 /etc/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';
}
?>
它返回:
nginx
Exist
NOT writable
我的 nginx 有以下配置:
/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