grollover
grollover

Reputation: 41

Php session files permissions

I have file index.php:

<?php    
session_start();
$_SESSION['favcolor'] = 'green';

And I get result:

Warning: session_start() [function.session-start]: open(/tmp/sess_a8njkmbcg3lbkvl7f2hhjchjm5, O_RDWR) failed: Permission denied (13) in /var/www/test.local/index.php on line 9
Warning: Unknown: open(/tmp/sess_a8njkmbcg3lbkvl7f2hhjchjm5, O_RDWR) failed: Permission denied (13) in Unknown on line 0
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

php.ini

root@savpc:/etc/php5/apache2# cat php.ini | grep '^session'
session.save_handler = files
session.save_path = "/tmp"
session.use_cookies = 1
session.use_only_cookies = 1
session.name = PHPSESSID
session.auto_start = 0
session.cookie_lifetime = 0
session.cookie_path = /
session.cookie_domain =
session.cookie_httponly =
session.serialize_handler = php
session.gc_probability = 0
session.gc_divisor = 1000
session.gc_maxlifetime = 1440
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

in file system i get files with strange permissions:

root@savpc:/tmp# ls -al | grep 'sess' 
----------  1 www-data www-data  2106 2013-11-11 19:21 sess_7cvcojv36n6se6mkrqmui7tu707u9avb
----------  1 www-data www-data    21 2013-11-11 19:23 sess_a8njkmbcg3lbkvl7f2hhjchjm5
----------  1 www-data www-data  1040 2013-11-11 19:21 sess_gllhhosb9dur0jdvf13lqe5klmebj1k9
----------  1 www-data www-data  2106 2013-11-11 19:21 sess_m8c788u0jssqg1gqjeonafk0er5jnbsk

In what can be the problem?

Upvotes: 4

Views: 17672

Answers (3)

Andrew
Andrew

Reputation: 1266

  1. Use a specific folder for sessions, such as /tmp/php_sessions. This is both good house keeping and for security reasons.

  2. Try specifying the file mode in session.save_path.

    session.save_path = "0;0600;/tmp/php_sessions"
    

    See session configuration in the PHP manual for more information on this.

Upvotes: 5

user2930889
user2930889

Reputation:

session.save_path = "D:/wamp/tmp"
<br>
D:/wamp/tmp  Change Temp Directory Or Give Permission up in this directory
<br>
PHP Cannot Access to This folder in Your Server...
<br>
D:/wamp/tmp !!! is Sample Directory

Find session.save_path or change Access...

Upvotes: 1

Tim Holum
Tim Holum

Reputation: 737

Try to make a different folder chown it to www-data and set the save path to that

also see if there is a umask setting in your php. I ni if so set it to 022

Upvotes: 0

Related Questions