Answers.Body: <p>If you can't enforce sticky sessions, then you'll need to provide a common place for all load balanced web server to save their PHP session files.</p>
  
  <p>By default PHP session files are file based and saved to whatever path the php.ini <a href="http://php.net/manual/en/function.session-save-path.php" rel="nofollow noreferrer">session_save_path</a> is set to.  You could change that to an NFS share path.</p>
  
  <p>If you had an in-memory key=>value store (like Redis, Memcached, etc.) you could configure PHP to save its sessions there.</p>
  
  <p>If you wanted something more persistent, you could configure PHP to save sessions in a database.</p>
  
  <p>On top of that, if you're not using stick sessions, you'd want to set a consistent <a href="https://craftcms.com/docs/config-settings#appId" rel="nofollow noreferrer">appId</a> and <a href="https://craftcms.com/docs/config-settings#validationKey" rel="nofollow noreferrer">validationKey</a> across every web server so they can decrypt Craft/PHP cookies using the same tokens.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-26T15:15:54.807Z
Answers.Text: Hey Brad, we currently have php sessions saving to the generic /var/lib/php/session/ directory. NFS share path could be a possibility. We also use MemcacheD as our 'cacheMethod'. How would I go about setting php sessions to use MemcacheD? Both servers use the same cache server so that would be a common ground. We also currently have the appID and validationKey set consistent across all load balanced servers.  Thanks, Adam
Answers.UserDisplayName: Adam Irinaga
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-26T18:10:27.903Z
Answers.Text: You'd have to set a custom `session.save_handler` and `session.save_path`. Similar to examples here https://www.digitalocean.com/community/tutorials/how-to-share-php-sessions-on-multiple-memcached-servers-on-ubuntu-14-04
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-26T18:15:13.230Z
Answers.Text: Thanks, just found a few of those tutorials.. Looks like there's a bug with php7 and or the version of memcacheD I'm using. Currrently getting : Failed to create session ID: memcached. With the hander and save_path set. I can create telnet connections from my web-server to my memcache servers just fine.
Answers.UserDisplayName: Adam Irinaga
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-25T18:22:05.473Z
Answers.LastActivityDate: 2017-07-25T18:22:05.473Z
Answers.UserDisplayName: Brad Bell
Body: <p>We are load balancing 2 servers hosting an identical Craft environment.</p>
  
  <p>When clicking around in the admin a user will get logged out after 30 seconds and sometimes even faster when browsing in the admin panel.</p>
  
  <p>I am unable to set the load balancer to sticky sessions due to the load balancer sitting behind a Firewall which NAT's inbound traffic. So the load balancer see's all inbound traffic as a single IP.</p>
  
  <p>Is there anything else that can be done to resolve this issue?</p>
  
Tags: <nginx><load-balancer>
Title: Load Balancing Craft CMS - Admin gets logged out instantly
ThreadText: # Load Balancing Craft CMS - Admin gets logged out instantly
  
  (Asked by: username_0 on 2017-07-25)
  
  We are load balancing 2 servers hosting an identical Craft environment.
  
  When clicking around in the admin a user will get logged out after 30 seconds and sometimes even faster when browsing in the admin panel.
  
  I am unable to set the load balancer to sticky sessions due to the load balancer sitting behind a Firewall which NAT's inbound traffic. So the load balancer see's all inbound traffic as a single IP.
  
  Is there anything else that can be done to resolve this issue?
  
  **Tags:** nginx, load-balancer
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-07-25. Score: 2
  
  If you can't enforce sticky sessions, then you'll need to provide a common place for all load balanced web server to save their PHP session files.
  
  By default PHP session files are file based and saved to whatever path the php.ini [session\_save\_path](http://php.net/manual/en/function.session-save-path.php) is set to. You could change that to an NFS share path.
  
  If you had an in-memory key=>value store (like Redis, Memcached, etc.) you could configure PHP to save its sessions there.
  
  If you wanted something more persistent, you could configure PHP to save sessions in a database.
  
  On top of that, if you're not using stick sessions, you'd want to set a consistent [appId](https://craftcms.com/docs/config-settings#appId) and [validationKey](https://craftcms.com/docs/config-settings#validationKey) across every web server so they can decrypt Craft/PHP cookies using the same tokens.
  
  > **Comments:**
  > **username_0**: Hey username_1, we currently have php sessions saving to the generic /var/lib/php/session/ directory. NFS share path could be a possibility. We also use MemcacheD as our 'cacheMethod'. How would I go about setting php sessions to use MemcacheD? Both servers use the same cache server so that would be a common ground. We also currently have the appID and validationKey set consistent across all load balanced servers.  Thanks, username_0  
  > **username_1**: You'd have to set a custom `session.save_handler` and `session.save_path`. Similar to examples here https://www.digitalocean.com/community/tutorials/how-to-share-php-sessions-on-multiple-memcached-servers-on-ubuntu-14-04  
  > **username_0**: Thanks, just found a few of those tutorials.. Looks like there's a bug with php7 and or the version of memcacheD I'm using. Currrently getting : Failed to create session ID: memcached. With the hander and save_path set. I can create telnet connections from my web-server to my memcache servers just fine.  
  
  ---
  
  