Monday, December 28, 2015

Phusion Passenger x Rails Composer

I host my customers' websites in VPS servers rented from HOST1PLUS (, and I use Apache webserver with Phusion Passenger module to do so.

Up  to this point, nothing so special. But a few days ago I started testing Rails Composer ( Everything worked great while I was using my development environment with Webrick, but when I finally tried to publish a small test app in one of my VPS servers, nothing worked.

Rails Composer offers the option to install better-errors, a wonderful gem. It displays a details' screen with all about your errors, which is great, considering that debugging requires all information available sometimes. And when it comes to web apps, you may say this again, and again...

Well, I installed better-errors and when I first tried to run my app I got just the dump screen with error details!

It said, sumarizing, that gem nokogiri could not be loaded. Strange, 'cause I had executed 'bundle install' and knew all gems were there. I followed the procedure to empty my gemset and then installed everything again. Nothing... Same error.

I tried almost everything I could imagine. Then, suddenly an idea came to my mind.

It happens that Rails Composer uses the strategy of creating a private gemset for each web app. The gemsets are stored under .rvm directory and we have always a global gemset for each Ruby version installed and as many private app gemsets as you create.

But be careful!

It seems that Phusion Passenger does NOT recognize private app gemsets. I tried almost everything, as I said before, including changing permissions. Nothing helped! But when I changed back to global gemset it all worked fine.

In order to move back you just have to edit .ruby-gemset file, which is under your app root directory. Remove whatever is written there and write just the word 'global' (no quotes, please).

After doing this, just run 'bundle install' again and you'll see all your gems which were installed in the private genset being installed again, now in the global gemset.

In the next article I'll discuss the advantages and problems of having private gemsets for each app. 

See you there.