Heroku Quickstart Guide
Heroku is a new approach to deploying web applications. Forget
about servers; the fundamental unit is the app. Develop locally on your
machine just like you always do. When you’re ready to deploy, use the Heroku
client gem to create your application in our cloud, then deploy with a
single git push. Git allows you to have multiple source repositories all
at the same time. By making Heroku just another source repository, you can
push your code and deploy your application in one easy step.
Prerequisites
Before using Heroku there are three simple requirements:
Run your Ruby application locally: Getting Started with Rails, Developing Rails apps on Mac OS X
Install Git: On a Mac, Windows, or UNIX/Linux
Getting your app on Heroku
Now that you have your application running locally, let’s deploy it to Heroku:
1. Track your application with Git
If you’re already using Git with your application, skip to the next step. If you’re not yet using Git to track your application, run this:
$ git init
Initialized empty Git repository in .git/
$ git add .
$ git commit -m "new app"
Created initial commit 5df2d09: new app
44 files changed, 8393 insertions(+), 0 deletions(-)
2. Create your application on Heroku
At the command line, run “heroku create”. When prompted for credentials, use the username and password from when you signed up; they’ll be saved on ~/.heroku/credentials so that you aren’t prompted on future runs. It will also upload your public key to allow you to push and pull code.
$ heroku create
Enter your Heroku credentials.
Email: joe@example.com
Password:
Uploading ssh public key /Users/joe/.ssh/id_rsa.pub
Created http://high-sunrise-58.heroku.com/ | git@heroku.com:high-sunrise-58.git
Git remote heroku added
Looking at the second to last line, you can see your app is called “high-sunrise-58”, and is available at http://high-sunrise-58.heroku.com. If you visit that URL now, you’ll see a standard welcome page, until you push your application up. The second URL – git@heroku.com:high-sunrise-58.git – is for the Git repository. Normally you would need to add this as a git remote; the “heroku create” command has done this for you automatically.
3. Push your application to Heroku
$ git push heroku master
Counting objects: 65, done.
Compressing objects: 100% (58/58), done.
Writing objects: 100% (65/65), 80.54 KiB, done.
Total 65 (delta 14), reused 0 (delta 0)
-----> Heroku receiving push
-----> Rails app detected
Compiled slug size is 0.1MB
-----> Launching....... done
App deployed to Heroku
To git@heroku.com:vivid-mountain-91.git
* [new branch] master -> master
4. Bootstrap your database
Your app is now running on Heroku with an empty database. Depending on your framework, run the appropriate command to setup your DB. For Ruby on Rails, run:
$ heroku rake db:migrate
(in /mnt/home/slugs/41913_b81cc1e5813c58c443e4120aff984d006f36ef20/mnt)
== 20081118092504 CreateWidgets: migrating ====================================
-- create_table(:widgets)
-> 0.0519s
== 20081118092504 CreateWidgets: migrated (0.0520s) ===========================
That’s it, your app is now running on Heroku!
Run heroku open to open your site in your default web browser.
Next steps
Now that your application is running you can push updates anytime with three easy steps:
- Develop and test changes locally.
- Commit code to git.
- Push your changes to Heroku with
git push heroku.