17

I switched servers recently, and now my home page won't work. It gives the following text:

Warning: session_start() [function.session-start]: open(/var/lib/php/session/sess_eqbchncji8kj22f0iqa9g3v7u2, O_RDWR) failed: Permission denied (13) in /var/www/vhosts/alt.alternativedc.com/httpdocs/index.php on line 6

Warning: Unknown: open(/var/lib/php/session/sess_eqbchncji8kj22f0iqa9g3v7u2, 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 (/var/lib/php/session) in Unknown on line 0

I assumed that this meant that the session folder was not writable, so I ran the following command after I ssh-ed into the server:

chmod o+rw /var/lib/php/session

That didn't seem to solve the problem. Not sure what to do now...

5
  • Does that particular session file exist? You may have to chmod all the session files in there as well.
    – Marc B
    Jul 8, 2011 at 17:45
  • "didn't seem to solve the problem." What does that mean?
    – webbiedave
    Jul 8, 2011 at 17:47
  • @webbiedave Means nothing changed - the errors persisted. @Marc B not sure I can do that. I think PHP creates a new file for each session ID. I cannot anticipate session IDs. not sure if I am right, though... Jul 8, 2011 at 17:50
  • @BlackSheep: Marc B simply means to also run chmod o+rw /var/lib/php/session/* then try again.
    – webbiedave
    Jul 8, 2011 at 17:52
  • @webbiedave Ran chmod o+rw /var/lib/php/session/*, got chmod: cannot access `/var/lib/php/session/*': No such file or directory Jul 8, 2011 at 17:59

7 Answers 7

27

Try changing your session save path in your php config file, /tmp is a good location.

php.ini

session.save_path = /tmp

http://www.php.net/manual/en/session.configuration.php#ini.session.save-path

3
  • Works great on OSX 10.10
    – smerten
    Sep 28, 2015 at 10:35
  • 3
    "Warning: If you leave this set to a world-readable directory, such as /tmp (the default), other users on the server may be able to hijack sessions by getting the list of files in that directory."
    – jgraup
    Feb 2, 2016 at 19:32
  • In my case I just needed to remove the "3;" from the default session.save_path = "3;/var/lib/php/sessions"
    – John Doe
    Mar 1, 2018 at 20:59
19

Just had the same issue on CentOS:

chown -R apache:apache /var/lib/php/session

Making the httpd user the ower of the session directory should work, as well.

1
  • 1
    This is the true exact answer concerning the problem with /var/lib/php/session/
    – Kyobul
    Dec 3, 2014 at 23:24
7

You probably changed a parent folder's permissions recursively, most likely to your own user.
Go to your sessions folder:
cd ~;cd /var/lib/php/

If you find a sessions folder, just write these two commands in your terminal:
cd ~; to go home, then
sudo chown -R www-data:www-data /var/lib/php/session

Or, if your sessions folder is "sessions" instead of "session":
cd ~; to go home, then
sudo chown -R www-data:www-data /var/lib/php/sessions

This way your server will be able to write sessions into your project.
I'm Quite sure about this approach.

0
2

both of tmp and /var/lib/session must be chmod 1777

and problem solved.

2
  • 4
    Welcome to Stack Overflow. When you answer a question, please format your answer nicely (spelling, grammar, punctuation). In this case, also explain what chmod 1777 does, and better yet, explain it in more generic terms also, like "make sure that /tmp and /var/lib/session are writable. Apr 24, 2013 at 20:20
  • 1777 permissions can be risky. unix.stackexchange.com/questions/64126/… Sep 4, 2018 at 1:27
2

Try changing the owner of the session directory to www-data. To do this run this command sudo chown -R www-data /var/lib/php/sessions. This works for me.

1
  • change www-data with your user:group and it works! Jan 31, 2021 at 23:59
1

I tried all the solutions here but they didn't work, because php.ini was being overwritten by other configs.

To find the culprit I used this trick:

grep -lR 'php_value' /etc/

And there it was /etc/httpd/conf.d/php.conf messing it up. So I changed its value from php_value session.save_path "/var/lib/php/session" to php_value session.save_path "/tmp".

After restarting Apache (service httpd restart) it finally worked!

0

on ubuntu 12.04 /var/lib/php5 has 1733 permission I change in php.ini session.save_path to /tmp to correctly store sessions alternatively you can set parameter in your code by ini_set('session.save_path',path_where_apache_have_permission_777);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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