How To upload a Rails app to Heroku

Posted by Daniel Vela on April 01, 2012 · 2 mins read

1 First, configure your app to use PostgreSQL: Edit your Gemfile to change the line :

gem 'sqlite3'

To this:

gem 'pg'

and execute:

$ bundle install

2 Second, use git to create a local repository:

$ git init
$ git add .
$ git commit -m "new app"

3 Third, install Heroku gem, if it isn’t installed yet:

$ gem install heroku
$ heroku list   

4 Now create the Heroku app:

$ heroku create
$ git push heroku master
$ heroku run rake db:migrate

5 To rename the default Heroku app name:

$ heroku rename <newname>

6 To create a custom domain for the app:

$ heroku addons:add cutom_domains
$ heroku domains:add <new.domain.com>

Next steps

  1. Develop and test locally
  2. Commit to git every change
  3. Push to Heroku with: $ git push heroku master

Utilities

  1. Rename Heroku app $ heroku rename
  2. Custom domain $ heroku addons:add custom_domains $ heroku domains:add
  3. Add the following text to Gemfile to user Thin server instead of WebBrick: gem ‘thin’
  4. How to install PostgreSQL on Mac
  5. Sample file config/database.yml to use PostgreSQL:
development:
  adapter: postgresql
  encoding: unicode
  database: blog_development
  pool: 5
  username: <set $USER>
  password:
  host: localhost
test:
  adapter: postgresql
  encoding: unicode
  database: blog_test
  pool: 5
  username: <set $USER>
  password:
  host: localhost

For Heroku production: entry is not necessary, because Heroku assigns one PostgreSQL to each app.