I recently made the move from Linode to Heroku for my personal sites. The last time I checked out Heroku was about 2 years ago, which I later dismissed because at the time it seemed like having your own VPS was the right thing to do.
Having your own VPS sounds good in theory, but in reality it’s not, for me at least. I liked being able to throw up random projects, host my friends projects, and tinker with new frameworks and languages. I maybe did that once or twice out of the 4 years I had my own VPS. In reality, I’m way to busy to do any of that. I started to get lazy on updates, and security patches. The traffic my personal sites receive are so minimal they don’t need a VPS.
After my week at the Aloha Ruby Conf, I noted to myself to check out Heroku once again, to see what has changed. To my surprise, A LOT has changed. There’s the new cedar stack, updated gem which is really awesome to use, procfile, etc, I could go on.
Anyway, I read through all their documents, which are amazingly good, and then signed up to try their free tier, 1 Dyno, which seems like a perfect size for my site.
The first thing I had to do was switch my applications database from MySQL to PostgreSQL because Heroku has native support for PostgreSQL. You can use MySQL through one of their add-ons if you wish.
Then I got my site up on Heroku by logging in and deploying.
I really like Unicorn(http://unicorn.bogomips.org) as my webserver and was excited to see that they fully support it, and all I needed to do was add one line to my Procfile. I also want to mention that even though 1 Dyno is supposed to only have 1 level of concurrency, with Unicorn I can have multiple concurrency.
Add Unicorn the Gemfile.
I added a Unicorn config file to my project by creating
config/unicorn.rb. In the file I can configure the number of workers and timeout.
Now that Unicorn is set up, Heroku needs to use Unicorn instead of its default web server. To tell Heroku to use Unicorn, they’ve provided the Procfile. I created a file named
Procfile in the project root directory. Inside the web server can be configured.
After that’s pushed to Heroku, I can check to make sure Unicorn is running by using
$ heroku ps.
I also needed access to cron or something similar to schedule my nightly Rake that updates the photos on the front page to my latest Flickr photos. Once again that took me a few minutes to set up through their web interface.
First I created my rake task in
lib/tasks/flickr_update.rake. It’s a simple script that updates a table with the last 3 photos I posted to flickr. I’m using the gem ‘fleakr’ to do this. I have a RecentPhoto model that has the attributes: title, url(url to the photos flickr page), image_url(url to the exact location of the image file).
In the Heroku web application settings add the Scheduler add-on. Then add the heroku run command for that rake task.
That pretty much covers my move from Linode to Heroku. I highly suggest reading through the Heroku documents.