PHP Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/tmp)

This article referring to another article that not published yet, I had some issue with session.save_path in php-fpm setup. For security improvements¬† I want to make PHP execute under individual user accounts insted of a system user like nginx (default www user and group). In apache environments I can use suPHP or suExec and in Nginx I can use php-fpm with custom “pool” each web server and that makes PHP scripts executed by owner and groups that describe in each pool.
But I got the following error message when try to installing some cms, and how to solve?

2011/12/03 23:49:34 [error] 1330#0: *126 FastCGI sent in stderr: “PHP Warning:¬† Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/tmp) in Unknown on line 0″ while reading upstream, client: 192.168.0.13, server: localhost, request: “GET /lgz/src/index.php HTTP/1.1″, upstream: “fastcgi://127.0.0.1:9000″, host: “172.16.0.1″, referrer: “http://172.16.0.1/lgz/src/login.php”
2011/12/03 23:54:34 [error] 1333#0: *208 FastCGI sent in stderr: “PHP Warning:¬† Unknown: open(/tmp/sess_ig3mpbuc2fuhjt1p4ibpe3maa4, O_RDWR) failed: Permission denied (13) in Unknown on line 0″ while reading upstream, client: 192.168.0.13, server: localhost, request: “GET /lgz/src/index.php HTTP/1.1″, upstream: “fastcgi://127.0.0.1:9000″, host: “172.16.0.1″, referrer: “http://172.16.0.1/lgz/src/login.php?referer=%2Flgz%2Fsrc%2Findex.php”
2011/12/03 23:54:34 [error] 1333#0: *208 FastCGI sent in stderr: “PHP Warning:¬† Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/tmp) in Unknown on line 0″ while reading upstream, client: 192.168.0.13, server: localhost, request: “GET /lgz/src/index.php HTTP/1.1″, upstream: “fastcgi://127.0.0.1:9000″, host: “172.16.0.1″, referrer: “http://172.16.0.1/lgz/src/login.php?referer=%2Flgz%2Fsrc%2Findex.php”

I’m sure that the /tmp permission are correct, but in fact I can’t use cookies to process authentication method. The problem is in my pool configuration and I need to add custom php rules here:

php_admin_value[session.save_handler] = files
php_admin_value[session.save_path] = “/tmp”
php_admin_value[session.use_cookies] = 1
php_admin_value[session.name] = PHPSESSID

After uncommented the lines in above, php scripts was success to execute and allowed use cookies in /tmp. This is stupid mind because I haven’t read the manpage before start using pool even my another websites running well, it’s habit (trying before RTFM, and RTFM after see an error). Below is an example of my php-fpm pool configuration:

[site1]
listen = 127.0.0.1:9000
listen.backlog = -1
listen.allowed_clients = 127.0.0.1
;listen.owner = nginx
;listen.group = nginx
;listen.mode = 0666
user = site1
group = site1
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 200
access.log = log/$pool.access.log
access.format = %R – %u %t “%m %r%Q%q” %s %f %{mili}d %{kilo}M %C%%
;request_terminate_timeout = 0
request_slowlog_timeout = 20
slowlog = log/$pool.log.slow
env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp

#add your custom php.ini
php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f [email protected]
php_admin_value[memory_limit] = 256M
php_admin_value[session.save_handler] = files
php_admin_value[session.save_path] = “/tmp”
php_admin_value[session.use_cookies] = 1
php_admin_value[session.name] = PHPSESSID

Don’t forget to restart php-fpm after change the configuration :)

reference: http://http://php-fpm.org/wiki

About David

Just nobody :-)
This entry was posted in Linux and tagged , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>