PHP cannot read sessions from an NFS share

I store my PHP session files on an NFS share. The problem is that PHP always creates an empty session file, but cannot read / write from it, so a new file is created for each page reload.

If I move the session store path to a local folder, the sessions are saved normally. I also start another environment with the same configuration, and it works fine.

On the same server where PHP has this problem, I can create / write / read files in the same directories where the sessions are saved (tested using root, non-root and specifically for the www-data user).

I am using PHP 5.5.12, Apache 2.4.9 and NFS v3 on Ubuntu 12.04 LTS

My php.ini

session.save_handler = files
session.save_path = "2;/mnt/cache/sessions"
session.use_cookies = 1
session.use_only_cookies = 0
session.name = PHPSESSID
session.auto_start = 0
session.cookie_lifetime = 2592000
session.cookie_path = /
session.cookie_domain =
session.cookie_httponly =
session.serialize_handler = php
session.gc_probability = 1
session.gc_divisor = 1000
session.gc_maxlifetime = 2592000
session.bug_compat_42 = Off
session.bug_compat_warn = Off
session.referer_check =
session.entropy_length = 0
session.cache_limiter = nocache
session.cache_expire = 180
session.use_trans_sid = 0
session.hash_function = 0
session.hash_bits_per_character = 5

My / etc / fstab

nfs-srv.local:/export/cache   /mnt/cache   nfs    rw,hard,intr  0  0

My / etc / exports on nfs-srv.local

/export/cache 10.1.10.0/24(rw,nohide,insecure,no_subtree_check,async,all_squash,anonuid=33,anongid=33)

Session Files

ls /mnt/cache/sessions/ -l
drwxrwxrwx 34 nobody nogroup 4096 May 16 10:33 0
drwxrwxrwx 34 nobody nogroup 4096 May 16 10:33 1
drwxrwxrwx 34 nobody nogroup 4096 May 16 10:33 2
...

ls /mnt/cache/sessions/m -l
drwxrwxrwx 2 nobody nogroup 4096 May 16 10:33 0
drwxrwxrwx 2 nobody nogroup 4096 May 16 12:18 1
drwxrwxrwx 2 nobody nogroup 4096 May 16 10:33 2
drwxrwxrwx 2 nobody nogroup 4096 May 16 10:33 3
drwxrwxrwx 2 nobody nogroup 4096 May 16 12:16 4
drwxrwxrwx 2 nobody nogroup 4096 May 16 12:14 5
...

ls /mnt/cache/sessions/m/5 -l
-rw------- 1 nobody nogroup 0 May 16 12:14 sess_m5ifehvhkjdisp7dgtiuu601e2
+4
2

, , PHP 5.5.10 5.6.5.

PHP 5.5.12 :

session.save_path - , (, Debian), , , chmod 666 - , . Webapp , . : fstat(), uid, . getuid(), uid 0, .

, , , Apache root. , NFS , UID/GID . , Apache , . , PHP 5.5.12 ( 5.4.28, "" ) NFS-.

+5

idmapd / /etc/nsswitch.conf. NFS /, idmapd .

www- NFS, NFS. /etc/passwd /etc/group, , www-, ldap nis- / /etc/nsswitch.conf.

.

0

Source: https://habr.com/ru/post/1540839/


All Articles