Posts Tagged ‘Heroku’
Heroku: Rails in the Cloud
Posted on November 16th, 2008 • Filed under Linux, Web Design • 3 Comments
This past summer, I landed a job writing web applications in Ruby on Rails. I had no Rails experience beforehand, but I soon realized how intuitive and enjoyable Rails can be. I was learning to organize my code more effectively by simply learning how to use the Rails framework. By the end of the summer, I had fallen in love with Rails.
I recently received an excited email from a summer colleague regarding a new web start-up called “Heroku.” In a nutshell, Heroku allows users to develop and test Rails applications from a web interface, keeping everything accessible and editable from the browser. In addition, users can work locally and update their projects with the Git version control system. The projects are hosted for free by Heroku (potentially with paid subscriptions once it is out of beta), so getting an application up and running is pretty effortless.
I’ve started hosting some of my apps on Heroku. Perhaps Heroku’s web interface will see some updates, but right now I find it clunky and often annoyingly slow. Instead, I prefer local edits, because once set up, navigating files and code is much faster on my laptop, and I don’t have to be online to develop my application. The following tutorial should explain how to get started with Heroku and work on Rails applications from a local machine.
But first…
Unless you’ve been trapped in some sort of time paradox for the past couple years and have just now emerged, you’ve probably heard of Ruby on Rails. However, if you have no idea how a Rails application works, I would recommend checking out some of the tutorials on the Rails Homepage. Otherwise, keep reading, and start experimenting with your own Heroku-hosted Rails application.
Note: At this point, I will assume that you have familiarized yourself with Rails and have at least installed Rails and RubyGems.
Windows Users: You may need to play around to get this tutorial working in your command prompt. In fact, it may not be possible yet to work locally from Windows. I’m currently writing this tutorial from Ubuntu, but it should work in OS X as well.
Step 1: Sign up for an account
Go to heroku.com, hit “login” and then click on “sign up.” There is currently a waiting list, which for me took about 10 minutes. However, if you find yourself waiting a long time, leave a comment asking for an invite and I’ll try to get you one.
Step 2: Install and configure the Heroku gem
You can use Heroku’s web interface to create a new app and begin editing it. However, I prefer using the Heroku gem, which allows you to have full functionality from your local machine. To begin, go to your Mac or Linux terminal and type the following (Ubuntu users may need to add “sudo”):
gem install heroku
This should install the Heroku gem. At this point, you may need to configure your ssh to use RSA authentication. Run the following command:
ssh-keygen -t rsa
It should prompt you to save a file, which should look something like “/home/[username]/.ssh/id_rsa” (go ahead and type that in). This will create an RSA authentication file for accessing Heroku’s servers.
The Heroku gem should now be configured. Go ahead and type the command “heroku list” to test it out.
Step 3: Create a new Heroku app
Create the application on Heroku’s servers by running the following command:
heroku create [appname]
This should return the following line:
Created http://[appname].heroku.com/ |
git@heroku.com:[appname].git
Your application exists online at the returned URL. Take note of the Git address, as we’ll use it in the next step.
Step 4: Get a local copy runningRun the following command to copy your new application’s files to a local folder:
git clone git@heroku.com:[appname].git
This should set up a git repository in the folder “appname”, which will allow you to update files from both Heroku’s web interface and from your local machine. You could instead use the command “heroku clone” rather than “git clone,” but they both use “git,” so you may as well use the version control system directly.
Step 5: Start editing your application
Yep, that’s it. You should be ready to get things running at this point. Go ahead and start editing your application in TextMate, RadRails, gedit, or whichever text editor you prefer. You can also copy files over from another Rails application, if you are trying to get an existing app running on Heroku. To upload your local files to Heroku, make sure you have changed to your application’s directory (“…/[appname]/”) and type the following commands:
git add .
git commit -m “type your changes here”
git push
If you make changes with the Heroku web editor, you can download the files with the following command:
git pull
At this point, you should be able to use both sets of commands to keep your Rails application up-to-date between your computer and Heroku, or even across different computers.
Last Step (optional):
To make your application publicly available, run the following command.
heroku update myapp –public true –mode production
This will put your application in production mode. Heroku won’t allow any edits, but your application will run much faster.
Concluding Remarks:
The “gem” and “heroku” commands have many other features, all of which are worth exploring. For instance, once you have an application in production mode, you might find it useful to create a new Git branch for development purposes. You can synchronize it with a new Heroku app in development mode. When you are done developing on the branch, you can merge it back into your production application. All of this would take some complicated Git work beyond the scope of this tutorial.
Heroku seems very promising, and, while it’s certainly not the only service of its kind, it is definitely pushing the boundaries of web development. Hopefully we’ll begin to see even more sites focusing on cloud computing, as the potential uses have certainly not run dry.
For now, I really recommend giving Heroku a try, and if you haven’t yet fallen in love with Rails, go ahead and spend a few hours reading into it. Perhaps you’ll be as intrigued as I was. Perhaps not. Either way, Rails is definitely going to be around for a while.
EDIT:
Some of this tutorial is now outdated. Much of the functionality described has been relocated to Heroku Garden, while Heroku only uses Git. I would recommend reading the “Docs” page on Heroku for more recent info.
this title will change.


![welcome-aboard Test your app at [appname].heroku.com](http://blog.ngriffith.com/wp-content/uploads/2008/11/welcome-aboard-300x181.png)