Sameer Siruguri

My Blog

LAMP Adventure: Phusion Passenger From Soup to Nuts on Ubuntu

I am conducting a workshop on how to deploy Ruby on Rails apps on a (Ubuntu) virtual private computer (VPC.) We’ll be using AWS Free Tier instances (t1.micro) to do this. When you have a freshly initialized AWS Ubuntu instance, you have to install more than just the Apache server basics to get through the full installation. This post lists all the necessary steps.

I have already written two posts that are useful – how to create a Free Tier instance, and how to install Apache from scratch on a Ubuntu VPC. If you’re trying to install only Ruby/Rails apps on your VPC, then you don’t need to complete all the instructions in the second tutorial of course – specifically, you can skip installation of PHP (and WordPress, of course, unless you also want to blog about your awesome adventures once you’re done.) You can also skip installation of MySQL if you’re only going to test your installation using SQLite3.

The instructions for enabling Passenger on Apache that are published by Phusion are written very well, and are mostly complete. Here are some of the gotchas, though, that I ran into.

Packages You’ll Need

Apart from Apache (and MySQL, if you’re going to use it), you’ll need to install make because the Passenger installation script will attempt to compile some of the Apache module code it needs.

apt-get install make

Note that here, as in the rest of the tutorial, we’ll assume you have root access on your machine. If not, use sudo before each command.

I also like to install emacs for editing files, which you’ll have to do to change your Apache config later on:

apt-get install emacs23

Installing the Passenger Ubuntu module DEB repository itself requires some other packages:

apt-get install build-essential
apt-get install libcurl4-openssl-dev
apt-get install apache2-threaded-dev
apt-get install ruby-dev

You might find that the Ruby Development Headers (that is, installing ruby-dev, the last of the packages in the above list) won’t install. The recommended way of fixing this would be to install Ruby using .rvm, rather than using the default Ruby you get with the Ubuntu install. We won’t look into how you do that in this post, because it can get pretty complicated.

The other way out of this situation is to remove one of the Ruby versions you get with Ubuntu 12.04, namely version 1.9. It looks like Ubuntu installs 1)or maybe it’s just the default Ubuntu 12.04 AMI that AWS recommends when you launch a micro instance has both Ruby 1.8 and 1.9. If you remove the latter, then you can successfully install Ruby’s development headers.

If you did this, make sure you re-run the gem installation:

gem install passenger

Use Postgres

This part is optional because you don’t need Postgres to run a Rails app but you might as well look into this as you graduate to writing and deploying production grade. Some preliminary steps are listed in a different post in one of the bullet items – we will upgrade that post over time to make it more comprehensive.

Beef Up Your Machine

Running the Passenger install script will also require that you have at least 1GB of swap space. Here’s a page that is a good description of what swap space is, and how you add it to your VPS. If you don’t want to read that, all you have to do is run these three commands:

dd if=/dev/zero of=/swap bs=1M count=1024
sudo mkswap /swap
sudo swapon /swap

This adds a gigabyte of swap space to your VPC, which the Free Tier micro instance can accommodate.

Note that even after you’ve done this, compiling the Passenger script will take a while, so anticipate a 10 minute break when you can get coffee/a glass of wine/catch up on Facebook.

Once you’re done, the script will tell you how to modify your .htaccess or Apache configuration files. One note you should pay attention to from the Phusion documentation listed above is the following:

Finally, you should be aware that Phusion Passenger runs your application under the production environment by default, not development. You can change this using the RailsEnv option.

Happy Passengering!

 

References   [ + ]

1. or maybe it’s just the default Ubuntu 12.04 AMI that AWS recommends when you launch a micro instance

Single Post Navigation

Leave a Reply

Your email address will not be published. Required fields are marked *