Why do this manually?

I am aware that there are PaaS out there (Heroku, EngineYard, DotCloud) that allows developers to deploy Rails app easily without requiring you to understand what’s going on behind the scene. But, I still believe that it’s nice to know how to manually set up your own server and deploy your code manually in the cloud (this time, we are going to use AWS EC2). This is not to say that I dislike PaaS. In fact, I really like them and I think they’re really great solutions that save a lot of developers’ time.

I currently work for a company that does not use any of the aforementioned PaaS. I often have to write my own script or deploy tasks that would start/manage the application and whatnot. Although doing all this is more tedious, I like the visibility and the explicitness that it provides. Not too much magic, just plain old manual setup.

Ruby gems, DB, and other things that I will use in this post:

  • ruby-2.0.0-p353
  • Rails 4.0.1
  • EC2
  • Git
  • Passenger

New Rails App (Feel free to skip this)

I am not going to do too much for this part. All I want to do is create a new Rails application and change the root page to show a static text (Hello World). I am going to outline the steps but you should be already familiar with this process.

Open up your terminal and go to your project folder. Mine is ~/workspace. Create a new Rails project (we are going to call it ‘blogapp’) by running the following:

cd ~/workspace
rails new blogapp

Now, I am going to create a new git repository for this new app and store it in BitBucket (feel free to use GitHub).

cd ~/workspace/blogapp
git init
git remote add origin ssh://git@bitbucket.org/denniss/blogapp.git
git add . && git commit -m "First commit"
git push origin master

Next, we are going to create a controller and a view and have the routes specify the root to point to the index page.

rails generate controller pages index

Find the index.html.erb that is generated by the last command and add a Hello World to it. Go to your routes.rb and change the root to point to pages#index.

Blogapp::Application.routes.draw do
  root "pages#index"
class PagesController < ApplicationController
  def index

Try running your server locally and see that it works. Just for sanity check, this is what I see.


Using Passenger

Although WEBrick will work just fine for development, we are not going to use it for production environment. We want to use a web server that is more scalable and production-ready. You have several choices (Unicorn, Puma, Passenger), but, this time, we are going to use Passenger.

Add the passenger gem to your Gemfile

gem passenger

And run bundle install on your project directory so that it fetches the newly added gem.

bundle install

Now try running your app using Passenger by running

passenger start

You should see something like this in the Terminal


Go to localhost:3000 again on your web browser and you should be able to see your hello world page.

Remember to update your git repo

git add .
git commit -m "Add passenger gem for production"
git push origin master

Continue to part 2

Simple Slide Out Navigation Menu in iOS with Swift (Part 2)

Continuing from part 1, we are going to see how to switch the displayed view controller when one of the menu selections is tapped Continue reading

Subdomain with NGINX on Linode

Published on January 14, 2015