How to create a staging environment heroku

1 Comment

Short version

$ heroku fork --from stark-eyrie-15516 --to automated-tester-staging
$ heroku info -a automated-tester-staging
Git URL:
$ git push staging

Long version

Sometimes it’s nice to have a staging environment for your heroku app (i.e. staging, prod etc).

To create a fresh staging environment for your app we first need to fork it, and then create a git remote name like ‘staging’ and point it to your newly forked app.

1. Fork app

> heroku fork -a appname myapp-staging
Fork complete, view it at (i.e.
  • appname is the name of the heroku app you want to fork. If your’ve already created a heroku app, it will have a name like ‘warm-wave-1832’.
  • to see a list of your heroku apps type:
> heroku apps
  • yourapp-staging is the name of the staging app you want to create (must be unique to heroku, so something like myapp-staging)

2. Create git repos name and point it to your newly created staging environment.

Before you can add a remote to your staging repos, you need the git url.
You can get that by going:

> heroku info -a myapp-staging
Git URL:

Now simple create a new git remote and point it to your newly created staging URL above:

> git remote add staging

3. Test.

> git remote -v

staging (fetch)

You should now see x3 git remotes.
One for your original ‘heroku’ app.
One for your github repos ‘origin’.
And your new one – ‘staging’

If you want to get rid of the ‘heroku’ git remote and replace it with ‘prod’ do this:

> git remote rm heroku
> git remote add prod

Now the fun starts! You should now be able to do stuff like this:

> git push prod
> git push staging

And each will go to their own respective heroku instances.

How to create a named app in heroku


Follow these instructions if you want to create a customer named app in Heroku:


Note: This is different than mapping tranquil-beach-9125 to a real prod domain (i.e.
To do that you must first create a named app, then point that to your prod domain. ->

Short version
> heroku apps:create myapp
> git remote rm heroku
> git remote add herkou


Long version

Here’s how to create a named app in Heroku assuming you’ve already got one deployed on Heroku with a name like tranquil-beach-9125.

1. Create your named app.

> heroku apps:create myapp
Creating myapp… done, stack is cedar |

To see your list of apps:

> heroku apps

2. Point the git remote ‘heroku’ to your newly named app.

> git remote -v
heroku (fetch)
heroku (push)
origin (fetch)
origin (push)

This shows where your git remote heroku is currently pointing (to that hard to remember name heroku created for you when you first created your app).

We are going to remove that git remote name, and then point it back to the newly created named instance we just created.

> git remote rm heroku
> git remote add herkou

To add prod as a remote to this repos also go:
> git remote add prod

Voila! We are done. When you now check your git remotes, you should now see heroku pointing to your nicely named repos with origin still pointing to your github instance..

> git remote -v
herkou (fetch)
herkou (push)
origin (fetch)
origin (push)

3. Test it.

To test make a change to your local repos and check it in. Then push to new repos.

> git push heroku
> heroku run rake db:migrate

This will push your repos to your newly created app.

How to import heroku postgres locally from prod rails

1 Comment

Step 1: Setup Postgres locally and get working with your app.

Heroku db:pull only works if you have postgres setup locally on your machine.

Go here for some tips on how to do that.

Step 2: Find out your postgres database name.

Before you can run the db:pull command, you need to know what postgres calls your prod database.

Get the name of your app
$ heroku apps

Then get the name of your postgres instance
$ heroku addons –app yourappname | grep POSTGRES
heroku-postgresql:dev HEROKU_POSTGRESQL_ORANGE

Step 3: Export db from prod.

You are now ready to pull the db from prod. Note this is going to create a new local database (to ensure you don’t accidentally blow over anything).

$ heroku pg:pull HEROKU_POSTGRESQL_ORANGE –app

Step 4: Import locally.

Now you just need to point your local database.yaml file to the newly generated postgres instance just created.

  adapter: postgresql
  host: localhost
  encoding: unicode
  database: <newdatabase>
  pool: 5
  username: jrasmusson

Step 5: Voila! You are done.

Restart your web server, fire up your app, and you should now see prod data locally running on your box.

Have fun!

Links that help:

heroku db:pull no longer working – workaround

Leave a comment

I was disappointed when I discovered that the very handy heroku db:pull stop working for me after upgrading to Ruby 2.0 and Rails 4.0.

I got it going again – by basically reverting back to Ruby 1.9.3 and Rails 3.1.0.

Here are the steps on how to revert back with rvm.

$ rvm install 1.9.3
$ ruby -v
$ rvm use 1.9.3-p286
$ rvm gemset create rails310
$ rvm 1.9.3-p286@rails310
$ rails -v
$ gem install rails -v 3.1.0
$ rvm gemset list
$ heroku db:pull –app targetapp
$ gem install taps
$ gem install sqlite3
$ heroku db:pull –app targetapp

Voila! Done.

How to add a git remote to a heroku app


There are two concepts at play when adding a user friendly heroku name to a git repos.

There is the remote (git) and the app (heroku).

git remote

Git remotes are just aliases for git repositories. You can see what alias are currently setup for your git repos by typing:

> git remote -v

heroku (fetch)
heroku (push)
origin (fetch)
origin (push)

origin and heroku are the remotes – and their corresponding git repos.

origin is my git hub repos.
heroku is my remote name for my heroku git repos.

When I type:

> git push heroku

It pushes my code to the heroku git repos using the ‘heroku’ git remote name.

heroku apps

When you create an instance of your code base on Heroku, it gives your app a name. You can see your app names by typing:

> heroku apps

=== My Apps

And you can get more info (like it’s git url) by typing:

> heroku info -a secret-waters-xxxx

=== secret-waters-7537
Addons: heroku-postgresql:dev
Git URL:
Owner Email:
Region: us
Repo Size: 7M
Slug Size: 33M
Stack: cedar
Tier: Legacy
Web URL:

What we want to do is tie these things together.

Tying a remote to an app

Say I created a staging environment, and I want to replace the heroku generated name it gave me (like secret-water) with a nicer name like ‘staging’. Here is how I would do it.

> git remote add staging

Now when I list my apps I should see staging there:

> git remote -v

staging (fetch)
staging (push)

And I should be able to push to my staging environment with this:

> git push staging

If you make a mistake you can remove a remote with

> git remote rm staging

For more examples of these and other commands feel free to checkout my heroku cheat sheet:

How to upgrade to Rails4 with Heroku

1 Comment

Rails migrations are never easy. But the community does it’s best to help you out. Here are some tips that helped me migrate my app:

Watch this video by Ryan Bates – Upgrading to Rails4

Check out these links

And then see if you run into any other problems like these:

Asset pipeline fails when deploying to Heroku Rails4

If you get this kind of error message

Preparing app for Rails asset pipeline
Running: rake assets:precompile
rake aborted!
could not connect to server: Connection refused
Is the server running on host “” and accepting

Try this from the command line:

> heroku labs:enable user-env-compile -a

You can get the name of your app be typing:

> heroku apps

Images not showing up

If you deploy but no images show up try this:


config.cache_classes = true
config.serve_static_assets = true
config.assets.compile = true
config.assets.digest = true


Other things to try

SampleApp::Application.configure do
  config.serve_static_assets = true

Links that help

How to change heroku git remote


If case you ever need to map your git remote back to an existing url do this:

> git remote -v

heroku (fetch)
heroku (push)
origin (fetch)
origin (push)

Right now heroku is pointed at protected-reef. But I want it to point to:

To do that is use this command:

> git remote add heroku

> git remote -v
heroku (fetch)
heroku (push)
origin (fetch)
origin (push)


Update: If you don’t have your heroku remote created, do this:

> heroku create
> git remote set-url heroku

Heroku domains with Google App Engine

1 Comment

These are some notes to remind me how to spin up a new rails app, point it to a URL I bought from Google App Engine, and configure the DNS so my Heroku app points to my www domain.

1. Build your app.

2. Deploy it.

> heroku create –stack cedar
> git push heroku master
> heroku run rake db:migrate

Note the URL of the deployed app in Heroku

—–> Launching… done, v7 deployed to Heroku

3. Tell Heroku to point to your domain.

$ heroku domains:add
Adding to myapp… done

4. Login into your Google Apps Cpanel domain

5. Point to your heroku instance.

Domain settings -> Domain names -> Advanced DNS settings

Note your URL and password and log into GoDaddy to make DNS config changes.

-> Sign into DNS console

The modify the www setting to point to heroku instance.


That’s it! You are done.

Tips for sending email via Rails


Some reminders for how to configure email via a rails application.

Watch this:

Add this:


  config.action_mailer.delivery_method = :smtp
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.smtp_settings = {
    :address              => "",
    :port                 => 587,
    :domain               => '',
    :user_name            => '',
    :password             => 'xxx',
    :authentication       => 'plain',
    :enable_starttls_auto => true

  config.action_mailer.default_url_options = { :host => "" }

And ignore the Heroku blog post about emailing via gmail.

Links that help

– restart prod server

Git GitHub Heroku RubyOnRails How to

1 Comment

This is a github cheat sheet I created after going through Michael Hartl’s excellent getting start with git tutorial as part of his also excellent online RubyOnRails book.

For a more thorough walk through go here. For a quick fix read on.

Create new git repository

Assuming you’ve installed rails, git, created a github account, and have a rails app you want to put under version control, navigate to the root of your rails app and create a new git repository as follows:

$ git init

Then create an ignore file at the root (in this case using TextMate) and add the following

$ mate .gitignore


Add your files to the repository recursively

$ git add .

Do your initial commit

$ git commit -m "Initial commit"

Create your new repository in github using the github UI.

Then push (save) your application to github.

$ git remote add origin<username>/first_app.git
$ git push origin master

There. Your repository is setup!

Branch, edit, commit, merge

Create a new branch

$ git checkout -b myChanges

Make some changes (in this case rename a file)


If you’ve made a mistake, roll it back.

$ git checkout -f

Commit the change to your branch

$ git commit -a -m "Moved the README file"

Merge with master branch

$ git checkout master
$ git merge myChanges

Then push to git server

$ git push

Deploy Heroku

For details on Heroku setup go here.

To create an instance of your app on Heroku and deploy go:

$ heroku create
$ git push heroku master

Then push, deploy, and view your app regularly with:

$ git push
$ git push heroku
$ heroku open

Voila! You’re done!

Other handy git commands

status shows you what branch you are on in case you forget

$ git status
# On branch homepage
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)

log shows you a list of your commit messages

$ git log
commit 69197e9cb7c9b3bd8b8f53bf2bfb65419027c201
Author: foo <>
Date:   Tue Sep 7 05:41:20 2010 -0600

     Initial commit

branch shows you what branch you are currently on

$ git branch
* tutorial

You can delete old two ways. The first deletes the branch after you’ve committed your changes. The second abandons the branch and ignores any changes:

$ git branch -d topic-branch
$ git branch -D topic-branch

%d bloggers like this: