Laravel apps on Idealstack

We love Laravel at Idealstack - a lot of our code is written in Laravel.  Here's some tips and tricks of recomended settings for Laravel on the Idealstack/AWS platform

Sessions

Idealstack installs a custom session handler that saves sessions into a DynamoDB table.  This allows for load balancing across multiple different instances/containers.  

By default, laravel apps use their own session handler, which overrides this setting.  The default setting is to use the 'files' handler which stores sessions in files in the web root.  This does work with Idealstack, but doesn't work particularly well  as the files will be stored on an NFS share - this is both slow and liable to lead to weird race conditions if two containers try to write sessions at the same time.

We recomend that you either use one of Laravel's other session handlers - the redis and memcached handlers work well with AWS Elasticache instances, or use native sessions - this will then use the idealstack session handler.

To use native sessions in idealstack you can use https://github.com/talandis/laravel-native-session-driver

Email

Any of Laravel's mail drivers should work with Idealstack, but provided you enable it in the hosting plan, Idealstack will configure SES to send email. To use this you don't need to use the SES driver in laravel, you can use the 'sendmail' driver and avoid having to deal with any configuration.

Redis

Many things in Laravel can make use of Redis, eg for Caching, Broadcasting, Queues.  All of these work well with an Elasticache Redis instance.  To set one up create an elasticache instance in your own VPC and then use VPC-peering to connect it to Idealstack

Cron/Scheduled Tasks

In your site settings enable a scheduled task like this to run Laravel's scheduled tasks and queued jobs

SQS Queues

Laravel supports SQS as a queue driver (alternatively you can also use Redis or Database drivers as well) to use this from an Idealstack site you need to setup an IAM policy allowing access to the queue and then set that policy on the site. See Connecting AWS Resources using IAM policies