Skip to main content

Yet Another LEMP Vagrant DEV Machine

This is my latest LEMP dev build. It’s carefully crafted after days of tweaking to include the following:

  1. Ubuntu 14.04 LTS
  2. NGINX 1.8.0
  3. PHP 5.6 (latest, currently 5.6.9)
  4. Ruby 2.2.2 (via RVM)
    1. Compass
    2. Sass
    3. Bundler
    4. CYAML
  5. curl
  6. openssl
  7. xdebug
  8. Composer

You can find it here, be sure to update the variables in the bash script to your specific parameters.

Usage

 

Automate install and setup of RVM/Ruby with Compass/Sass in Vagrant

My teams use development environments powered by Vagrant, which I highly recommend. This however requires we either maintain or manage a variety of recipes/cookbooks, or that we bootstrap our dev virtual machines identically. I generally prefer the latter to avoid issues with connecting to Chef that have burned me in the past, or just general third-party woes. Bootstrapping an app then requires some scripting to properly setup Ruby and thereby Compass and Sass gems which we use for compiling our assets.

That being said, we’ve chosen to use RVM instead of rbenv or any of the alternatives just because it suits us best. I’m not evangelical one way or the other.

We’ve essentially taken this superb guide from AJ ONeal and made a crisp little bash script. Finally, the meat of the script. We put this in every bootstrap script to setup the basics of ruby/compass/sass:

 

Update User Entity on login

I recently built an app that required we update the authenticated user’s lastOnlineDate every session so we can quickly track who has been online in the last interval of time. We set this interval as a parameter and used that to avoid hitting the database more than absolutely necessary to accomplish this.

To make it work, we needed to leverage onSecurityInteractiveLogin:

app/config/parameters.yml

MyApp/EventListener/LoginListener.php

 

app/config/services.yml


Alternatives

In this particular use-case, leveraging a setContainer call may not be necessary if all you’re doing is setting a single value on a User entity. Alternatively, we could simply send the activity_minutes parameter as an argument to the service, and not use the container at all.

We’d have to adjust our LoginListener appropriately as well: