0

My website won't save PHP sessions properly, I originally posted on it in SO, but it's increasingly looking like a server issue. So, I figured I would re-phrase the question here.

Why would this PHP server config fail to save and retrieve sessions?

One of the key symptoms seems to be that PHP is not creating any files in /var/lib/php/session. Here are the current permissions form the server:

$ ls -al /var/lib/php/session/
total 28
drwxrwx--- 2 root apache 24576 Jul 20 13:30 .
drwxr-xr-x 3 root root    4096 Jul 20 13:30 ..

Here are some test URLs. This first link creates a session array and prints the output, the second just prints session output, but unfortunately it's blank.

http://barbadospropertylist.com/wp-content/plugins/gravitymeta/test.php?name=value

http://barbadospropertylist.com/wp-content/plugins/gravitymeta/test.php

jnthnclrk
  • 139
  • 1
  • 9

1 Answers1

0

I see you are using nginx and port 7080 for apache.

If ever your architecture includes multiple apache servers and some kind of load balancing, then you must do something for sessions to be shared accross multiple apache server (memcached, clever load balancing, nfs, mysql, ... ).

Edit #1

IMHO, as you have only one webserver, there is no reason for now to try using memcached for storing sessions.

At some point, you managed to configure php to use files to store sessions but session files were not effectively written /var/lib/php/session

That is why you loose session when you jump from one page to another.

/var/lib/php/session permissions are usually fine and sessions work out the box in most linux and bsd distro.

To check that permissions are ok do the following :

Step 1 : Check that php is configured to write to /var/lib/php/session using your url that calls phpinfo(). You should get something like :

Registered save handlers => files user
session.save_path => /var/lib/php/session

step 2 : Check under which user apache is running both with ps and by looking at config files.

You should obtain apache , www , www-data or http.

step 3 :

Check that apache user has write access to session path. This can be done by typing ls -ld /var;ls -ld /var/lib;ls -ld /var/php;ls -ld var/lib/php/session

or by effectively creating a file with apache user

su - www -s /bin/bash or su -m www

then

touch /var/lib/php/session/test

If permission is not the problem, we'll can try other stuff

  • I installed memcached. Didn't realise there was further config for sessions to work. Not sure if it's load balancing either. – jnthnclrk Aug 02 '12 at 12:39
  • Do you use multiple server? Is memcached supposed to share sessions between all your servers? Does session work if you use files to store them and only one web server? –  Aug 02 '12 at 13:26
  • Pretty sure it's only 1 server. I'll add some test pages to the question above now. Not sure how to use files to store sessions. – jnthnclrk Aug 02 '12 at 13:28
  • You seem to use files for session saving: `session.save_handler files session.save_path /var/lib/php/session`; Are there any file created in /var/lib/php/session while you use your test page? –  Aug 02 '12 at 13:43
  • # ls /var/lib/php/session is empty... – jnthnclrk Aug 02 '12 at 13:50
  • I also tried to set the handler in php.ini to: session.save_handler = memcache – jnthnclrk Aug 02 '12 at 13:52
  • The problem seems related to this question : http://stackoverflow.com/questions/4333209/session-start-hangs –  Aug 02 '12 at 14:43
  • Not really, my sessions aren't hanging. They are just not getting set between page loads. – jnthnclrk Aug 02 '12 at 16:20
  • Sorry if I was not precise enough : I never said that you are having exactly the same problem; I was just thinking there was a lot of clues in this page. For example, it's written that "/var/lib/php/session/ stays empty but permissions are absolutely fine". Have you double checked file permission on /var/lib/php/session/ ? Have you tried point C of the first answer? Is there some network file system somewhere? –  Aug 02 '12 at 17:28
  • Sorry, I didn't mean to be rude. Just one of those things that I thought would be easy and turns out it's anything but. I'm not sure what the permissions should be, I'll add the current permissions to the question. I don't really understand point C. – jnthnclrk Aug 02 '12 at 17:52
  • I'll edit answer to sum up everything, don't hesitate to ask more accurate answer if i'm not clear enough, as english is not my native langage. –  Aug 02 '12 at 18:22