Saturday, September 30, 2017

Nginx + Passenger + Ruby: Getting it to Work the First Time

Getting Ruby App Working for the First Time

Getting Nginx to run your Ruby app for the first time may be easy, but it likely will run into some difficulties. A very common problem from what I can see on the web is that some gem won't install. After quite a bit of digging and a little guessing I finally got it work. And in particular, I solved the common "bundle install" error. Since I could not find any reference to my particular solution on the web, I'm sharing it here.

Install

Nginx is install as is Fusion using the "setup and deploy" reference below. Worked well.

Run in Development Mode

Passenger was failing, but it was not telling me much because it was running in production mode. I wanted more detail right in the browser. I could have found a lot of detail either in /tmp (there were passenger logs there) and /var/log/nginx. But instead I set "rails_env" to "development" in /etc/nginx/sites-enabled/default and then I saw lots of details in the browser.

Error #1

I configured Nginx to run my app, and the first issue I ran into was found in /etc/nginx/passenger.conf: the "passenger_ruby" setting was set to some ruby that didn't exist. So, I set that value to the output of the "which ruby" command which happens for me to be /usr/local/bin/ruby.

Error #2

In one of the passenger log files in /tmp, I saw reference to a failure to run "make" This, it turns out, was not a fatal error, but I fixed it anyway by:

mkdir -p /home/<my user>/.passenger/native_support/5.1.8/ruby-1.9.3-x86_64-linux
cd /home/<my user>/.passenger/native_support/5.1.8/ruby-1.9.3-x86_64-linux
/usr/local/bin/ruby /usr/share/passenger/ruby_extension_source/extconf.rb

And then running "make" which produced the following files:

passenger_native_support.o
passenger_native_support.so

Error #3 and Final Solution

Now I was getting a bit further and hitting the seemingly typical "It looks like Bundler could not find a gem." error. I reviewed: https://www.phusionpassenger.com/library/admin/nginx/troubleshooting/ruby/#the-application-reports-during-startup-that-it-cannot-find-a-gem
but so far no joy. I looked closer at the error:

"git://github.com/rails/activerecord-session_store.git (at master@b5e7da2) is not yet checked out. Run `bundle install` first. (Bundler::GitError)"

I had run "bundle install" and "bundle update" many names for my application, and I looked in the "Gemfile" ans saw the following line:

gem 'activerecord-session_store', github: 'rails/activerecord-session_store'

Well, "bundle install" and even "bundle update" ran for me at a command line with no issue, but my application was still reporting the same bundle error. 

I happened to see something in "bundle help" and guessed it might help, so I ran:

bundle package --all

And that was the solution! App would finally come up.

What "bundle package --all" does

"bundle package" bundless all the .gem files needed to run the application in th the "vendor/cache" directory. Since my error involved "git" I included "--all" which also packages git and path directories. That didn't seem to be necessary, but I did it just in case.

For more information, run the "bundle help" or "bundle package --help" command.

Most helpful References



http://geekhmer.github.io/blog/2016/07/13/setup-and-deploy-ruby-on-rails-on-ubuntu-16-dot-04-or-latest/

Most helpful trouble shooting reference:

https://www.phusionpassenger.com/library/admin/nginx/troubleshooting/ruby/

Most specifically to my issue:

https://www.phusionpassenger.com/library/admin/nginx/troubleshooting/ruby/#the-application-reports-during-startup-that-it-cannot-find-a-gem


Sunday, April 16, 2017

Elementary OS: Free Installation

Don't be Intimidated

Elementary OS (https://elementary.io/) has received a reasonable amount of press. It's a Linux distro with a pretty face and has been getting positive reviews. BUT: it wants to know how much $$ you're going to pay before you proceed to download it. What? A Linux distro that costs $$? Well, that's the way it appears. And, if you download it and love it, you should consider contributing with a donation. But what if you just want to check it out first? Click on download and up pops a dialog to collect some money. Is there a free alternative? Yep:

BEFORE you click on download, click into the "Custom Amount" field and type 0.00 and then click on the Download button. The next dialog will let you click another Download button to get the download started. Once downloaded, if you run the .ISO file line any other distribution, you can "try" it (live CD) or "install" it. One way to both install and try it out of course it to create a new Virtual Machine using something like Oracle Virtual Box. You can install Elementary OS as well as Oracle Virtual Box without spending a dime.

For a nice introduction to this distro, see: https://en.wikipedia.org/wiki/Elementary_OS. Note that it's built on Ubuntu LTS.