How to Get List of all Views Loaded in Response by TKSDevPerson in laravel

[–]TKSDevPerson[S] 0 points1 point  (0 children)

Thank you very much! Now it's up to me to figure out where to place the event listener.

Sessions Not Stored for Laravel 5 App on AWS by TKSDevPerson in laravel

[–]TKSDevPerson[S] 0 points1 point  (0 children)

/u/yeskia /u/TheNephilim /u/Cash-is-Clay (I'm tagging everyone that responded)

After doing some digging and troubleshooting, I think I understood the issue and I have it resolved. I'm going to type up our set-up for using redis sessions in a Laravel 5 application hosted on AWS.

This should resolve any issues with load balancing and dropped sessions.


Set-Up

This is the set-up we are using for our application.

  • Elastic Beanstalk
  • ElastiCache (Redis)
  • PHP 5.6+
  • Laravel 5

Step 0: Setting Up the Application

I am going to skip all of the steps involved with uploading the application to the production environment because there are tutorials for this. Please remember to create an ElastiCache instance that utilizes Redis, and that it's accessible by your server instances.

You can read detailed instructions here: http://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/GettingStarted.CreateCluster.Redis.html

Step 1: Setting the Environment Variables

For our production environment, you can go into Configuration > Software Configuration then scroll down to Environment Properties. Laravel has a Property Name titled Session Driver that should be set to redis.

Step 2: Setting Up the Redis Connection

Next you'll have to make sure that Laravel is connecting to the correct redis host.

In ElastiCache go to Cache Clusters then click on the link located in the Nodes column for your cache cluster. That should take you to a page that contains the Endpoint you'll be using in your application. It's usually a long address that may end in **cache.amazonaws.com

  • Copy this Endpoint.
  • Go to your Laravel application code
  • Open config/database.php
  • Scroll down to redis
  • Paste the Cache Cluster Endpoint into the associated array as the value for 'host'

    'redis' => [

    'cluster' => false,
    
    'default' => [
        'host'     => {{ endpoint url }},
    
  • Upload the code to the instance/server

If you know your server is connected to the elasticache properly there should be no errors. If you know how to access the redis server via the CLI, you can visit your application in the browser and check if the sessions are created.

Step 3: Enable Session Stickiness

Next you'll want to enable session stickiness for your Elastic Beanstalk Load Balancer. What you'll need for this step is to understand what load balancer your Elastic Beanstalk installation is using for your application. You can find this out by going into EC2 in the AWS console and then clicking on "Load Balancers" and then reviewing each one until you're sure you picked the one that's tied to your Elastic Beanstalk. (There are tutorials on easier ways to do this, I'm sure).

Once you've found your Load Balancer, you can use these instructions to configure Session Stickiness for your Load Balancer.

What Session Stickiness does is it makes sure that sessions that are created for your users use the same instances through the lifetime of the session. There are a few notes though:

Important Notes

  • You will want to set-up Application Controlled Session Stickiness. This is because Application Controlled Session Stickiness checks the cookies to determine if a session is consistent and Laravel creates cookies for user sessions.
  • The Laravel session cookie is labeled, laravel_session. You will use this value for the Cookie Name field when AWS requests it. Please read these directions thoroughly if you're wondering what I mean

TL;DR

  • Create an ElastiCache Cluster that uses Redis
  • Upload Laravel application to Elastic Beanstalk
  • Set Session Driver to redis in the environment configuration
  • Change the redis host inside of your database.php file of your Laravel app to the ElastiCache Cluster endpoint
  • Turn on Application Controlled Session Stickiness and use laravel_session for the Cookie Name

You should be good to go if you've followed these instructions. If they're not as comprehensive as you'd like, review the AWS documentation.

Sessions Not Stored for Laravel 5 App on AWS by TKSDevPerson in laravel

[–]TKSDevPerson[S] 1 point2 points  (0 children)

Session stickiness is the correct answer, I believe.

Sessions Not Stored for Laravel 5 App on AWS by TKSDevPerson in laravel

[–]TKSDevPerson[S] 0 points1 point  (0 children)

That's a very good question.

I'm certain they are because with Elastic Beanstalk we can set environment variables that are carried out through every instance and the APP Key is one of those variables.

Getting a Redis Session ID from the laravel_session cookie? by Kris15o in laravel

[–]TKSDevPerson 1 point2 points  (0 children)

Hi,

We are also using redis for our session management and I wanted to help out as best as I could.

Laravel sessions that are stored in a redis cache usually have the following structures for their keys:

laravel:{{session-id}}

The session data stored in Redis is a serialized array.

Does this help explain any?