Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

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

share|improve this answer
    
I installed memcached. Didn't realise there was further config for sessions to work. Not sure if it's load balancing either. –  jnthnclrk Aug 2 '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? –  coincoin Aug 2 '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 2 '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? –  coincoin Aug 2 '12 at 13:43
    
# ls /var/lib/php/session is empty... –  jnthnclrk Aug 2 '12 at 13:50

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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