Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 381 lines (370 sloc) 29.496 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380
<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>Rails Heroku Tutorial &#183; RailsApps</title>
    <link href="https://plus.google.com/u/0/b/117374718581973393536/117374718581973393536/posts/" rel="publisher" />
    <link rel="stylesheet" href="http://railsapps.github.com/css/bootstrap.css" type="text/css" charset="utf-8" />
    <link rel="stylesheet" href="http://railsapps.github.com/css/screen.css" type="text/css" charset="utf-8" />
    <link rel="stylesheet" href="http://railsapps.github.com/css/gollum.css" type="text/css" charset="utf-8" />
    <link rel="stylesheet" href="http://railsapps.github.com/css/site.css" type="text/css" charset="utf-8" />
    <link rel="stylesheet" href="http://railsapps.github.com/css/syntax.css" type="text/css" charset="utf-8" />
    <script src="http://code.jquery.com/jquery-1.6.min.js" type="text/javascript"></script>
    <script src="http://railsapps.github.com/javascript/jquery.text_selection-1.0.0.min.js" type="text/javascript"></script>
    <script src="http://railsapps.github.com/javascript/jquery.previewable_comment_form.js" type="text/javascript"></script>
    <script src="http://railsapps.github.com/javascript/jquery.tabs.js" type="text/javascript"></script>
    <script src="http://railsapps.github.com/javascript/gollum.js" type="text/javascript"></script>
    <script type="text/javascript">
      var _gaq = _gaq || [];
      _gaq.push(['_setAccount', 'UA-5109366-14']);
      _gaq.push(['_trackPageview']);
      (function() {
        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
      })();
    </script>
  </head>
  <body>

  <div class="navbar navbar-fixed-top">
    <div class="navbar-inner">
      <div class="container">
        <a href="http://railsapps.github.com/" class="brand">RailsApps Project</a>
        <ul class="pull-right nav">
          <li><a href="http://blog.railsapps.org/" class="twitter">Blog</a></li>
          <li><a href="http://twitter.com/rails_apps" class="twitter">Twitter</a></li>
          <li><a href="https://plus.google.com/117374718581973393536" class="google">Google +</a></li>
          <li><a href="https://github.com/RailsApps" class="github">GitHub Repository</a></li>
        </ul>
      </div>
    </div>
  </div>

  <div class="container">

    <div class="content wikistyle gollum textile">
      <h1>Rails Heroku Tutorial</h1>
<h4>by Daniel Kehoe</h4>
<p><em>Last updated 18 July 2012</em></p>
<p>Here’s how to set up an app with Rails 3.2 and Ruby 1.9.3 on Heroku. Heroku provides low cost, easily configured Rails 3.2 application hosting.</p>
<p>An article, <a href="http://rdegges.com/heroku-isnt-for-idiots">Heroku Isn’t for Idiots</a>, describes why you might want to use Heroku. And a discussion on Quora explains, <a href="http://www.quora.com/What-are-the-potential-downsides-of-using-Heroku">What are the potential downsides of using Heroku?</a> (not many).</p>
<h3>RailsApps Examples and Tutorials</h3>
<p>This is a guide for developers using the example apps from the RailsApps repository. The RailsApps project provides open source apps and detailed tutorials for Rails developers. You may already have built an app that’s ready to deploy on Heroku; next time you build an app, check the <a href="http://railsapps.github.com/">RailsApps</a> project to see if we can save you some time with a starter app.</p>
<p><a href="http://www.twitter.com/rails_apps"><img src="http://twitter-badges.s3.amazonaws.com/t_logo-a.png" title="Follow on Twitter" alt="Follow on Twitter"></a> Follow <a href="http://twitter.com/rails_apps">@rails_apps</a> on Twitter for updates and timely Rails tips.</p>
<h2>Before You Start</h2>
<p>To deploy an app to Heroku, you must have a Heroku account. Visit <a href="http://heroku.com/">http://heroku.com/</a> to set up an account. Or you can use someone else’s account (such as a client’s or employer’s if you have login credentials); see details below.</p>
<p>Before you start, you should review the advice offered in the article <a href="http://railsapps.github.com/installing-rails.html">Installing Rails</a> to be sure your development environment is set up correctly on your local machine.</p>
<h2>Ruby 1.9.3 on Heroku</h2>
<p>Heroku’s newest stack, “Celadon Cedar,” supports Ruby 1.9.3 and Rails 3.2. As of 9 May 2012, Heroku officially supports Ruby 1.9.3 (see <a href="http://blog.heroku.com/archives/2012/5/9/multiple_ruby_version_support_on_heroku/">Multiple Ruby Version Support on Heroku</a>).</p>
<p>You configure the Heroku environment to use Ruby 1.9.3 by specifying the Ruby version in your application Gemfile. This requires use of the newest version of the <a href="http://gembundler.com/">Bundler</a> gem. You must install Bundler 1.1.5 or newer if you plan to deploy to Heroku (see instructions below).</p>
<p>You cannot specify a patch level for a Ruby version (such as ruby-1.9.3-p194). Heroku provides the most secure patch level of whatever minor version number you request.</p>
<p><em>Note:</em> You may have found outdated instructions elsewhere. To clarify: Installing Ruby 1.9.3 on Heroku previously (before March 19, 2012) required installation of the heroku-labs plugin. The heroku-labs plugin is deprecated and its functionality is now incorporated in the heroku client gem. Before May 9, 2012, installing Ruby 1.9.3 on Heroku required the <a href="http://devcenter.heroku.com/articles/labs-user-env-compile">user_env_compile</a> feature; this is now deprecated. Furthermore, it is no longer necessary to set the RUBY_VERSION variable with <code>$ heroku config:add RUBY_VERSION=ruby-1.9.3-p125</code> or to set the Heroku <span class="caps">PATH</span> config variable to include “bin” when you specify the default Ruby 1.9.3 for the Cedar stack. Prior to Rails 3.1.0.rc5, Heroku required an additional gem <code>therubyracer-heroku</code>. This gem is no longer needed for Rails 3.2 and should not be used.</p>
<p>The following Heroku articles on Rails 3.1 are helpful:</p>
<ul>
<li><a href="https://devcenter.heroku.com/articles/ruby-support">Heroku Ruby Support</a></li>
<li><a href="https://devcenter.heroku.com/articles/rails3">Getting Started with Rails 3.x on Heroku/Cedar</a></li>
<li><a href="https://devcenter.heroku.com/articles/rails3x-asset-pipeline-cedar">Rails 3.1+ Asset Pipeline on Heroku Cedar.</a></li>
</ul><h3>Updating Bundler for Heroku</h3>
<p>These instructions assume you are using rvm, the <a href="https://rvm.io/">Ruby Version Manager</a>. Bundler and rubygems-bundler are installed in rvm’s “global” gemset.</p>
<p>First, update to the <a href="http://rubygems.org/gems/rubygems-bundler">newest version of Rubygems-Bundler</a>.</p>
<pre>
$ rvm gemset use global
$ gem update rubygems-bundler
$ gem list
</pre>
<p>Then install Bundler version 1.1.5 (or newer).</p>
<pre>
$ rvm gemset use global
$ gem update bundler
$ bundle --version
</pre>
<p>If you encounter any issues when updating rubygems-bundler and Bundler, review the detailed instructions in the article <a href="http://railsapps.github.com/installing-rails.html">Installing Rails</a>.</p>
<p>Switch back to your application-specific gemset to proceed:</p>
<pre>
$ rvm gemset use &lt;whatever&gt;
</pre>
<h2>Preparing a Gemfile for Heroku</h2>
<p>You’ll add the Heroku gem and specify a Ruby version in your application’s gemfile.</p>
<h3>Specifying a Ruby Version</h3>
<p>Specify a Ruby version before specifying any gems:</p>
<pre>
source 'http://rubygems.org'

ruby '1.9.3'
gem 'rails', '3.2.6'
</pre>
<h3>Heroku Gem</h3>
<p>Add the Heroku gem to your application’s Gemfile <a href="http://rubygems.org/gems/heroku">(check rubygems.org for the latest heroku gem)</a>:</p>
<p><code>gem "heroku"</code></p>
<p>Install your gems with:</p>
<p><code>$ bundle install</code></p>
<p>If you haven’t done so, add your public key after installing the heroku gem so that you can use git to push or clone Heroku app repositories. For more information, see Heroku’s documentation <a href="http://devcenter.heroku.com/articles/keys">Managing Your <span class="caps">SSH</span> Keys</a>.</p>
<p><em>Note:</em> As an alternative to installing the Heroku gem, Heroku offers a stand-alone “Heroku Toolbelt” which installs the Heroku command-line client and the Git revision control system. You can use either the Heroku gem or the Heroku Toolbelt. For more information, see Heroku’s documentation <a href="http://devcenter.heroku.com/articles/heroku-command">Installing the Heroku <span class="caps">CLI</span></a>. It’s probably easier to simply use the Heroku gem.</p>
<h2>Database Configuration</h2>
<p>Heroku uses PostgreSQL as its default database. Heroku does not support SQLite or MySQL, the databases most commonly used for local development.</p>
<h3>Use SQLite Locally and PostgreSQL on Heroku</h3>
<p>As a general practice, you should use the same environment for local development as you do for production, which means using the same database systems locally and in production. In practice, with ActiveRecord isolating the database system, this may not be critically important.</p>
<p>If you don’t want to develop using PostgreSQL locally, you can set up your Gemfile to use SQLite for development and PostgreSQL for production. To switch from SQLite to PostgreSQL for deployment to Heroku, edit your Gemfile and change this line:</p>
<p><code>gem 'sqlite3'</code></p>
<p>To this:</p>
<pre>
group :development, :test do
  gem 'sqlite3'
end
group :production do
  gem 'pg'
end
</pre>
<p>Run <code>bundle install --without production</code> to update your gems. The flag <code>--without production</code> allows you to skip local installation of the pg gem; otherwise, you will have to install PostgreSQL locally (the pg gem won’t install if PostgreSQL is not installed).</p>
<h3>Use PostgreSQL Locally and on Heroku</h3>
<p>If you’d like to use PostgreSQL both locally and on Heroku for production, edit your Gemfile and change this line:</p>
<p><code>gem 'sqlite3'</code></p>
<p>To this:</p>
<p><code>gem 'pg'</code></p>
<p>You’ll have to install PostgreSQL locally before running <code>bundle install</code>.</p>
<h3>The MongoDB Alternative</h3>
<p>MongoDB simplifies development by eliminating the schemas and migrations required by SQLite, MySQL, or PostgreSQL. The <a href="http://addons.heroku.com/mongohq">MongoHQ</a> add-on is offered by Heroku and provides a hosted MongoDB datastore.</p>
<p>If you decide to try MongoDB, take a look at the example apps (with detailed tutorials) that combine <a href="https://github.com/RailsApps/rails3-mongoid-devise">Mongoid with Devise</a> or <a href="https://github.com/RailsApps/rails3-mongoid-omniauth">Mongoid with OmniAuth</a>.</p>
<h4>Configure Mongoid</h4>
<p>By default, the file <strong>config/mongoid.yml</strong> contains this:</p>
<pre>
development:
  # Configure available database sessions. (required)
  sessions:
    # Defines the default session. (required)
    default:
      # Defines the name of the default database that Mongoid can connect to.
      # (required).
      database: &lt;something&gt;
      # Provides the hosts the default session can connect to. Must be an array
      # of host:port pairs. (required)
      hosts:
        - localhost:27017
</pre>
<p>To use MongoHQ with your app, add the following to the file <strong>config/mongoid.yml</strong>:</p>
<pre>
&lt;% if ENV['MONGOHQ_URL'] %&gt;
  production:
    sessions:
      default:
        uri: &lt;%= ENV['MONGOHQ_URL'] %&gt;
        options:
          skip_version_check: true
          safe: true
&lt;% end %&gt;
</pre>
<h2>Specifying a Rails Server</h2>
<p>By default, when you run <code>rails server</code> locally, Rails launches the simple Webrick web server. For production apps Heroku recommends using a more robust webserver such as <a href="http://code.macournoyer.com/thin/">Thin</a>.</p>
<p>To use Thin, add the gem to your Gemfile:</p>
<p><code>gem 'thin'</code></p>
<p>If you want to continue to use Webrick as your local web server, with Thin on Heroku, set up your Gemfile like this:</p>
<pre>
group :production do
  gem 'thin'
end
</pre>
<p>Run <code>bundle install --without production</code> to update your gems.</p>
<h3>Procfile Not Needed</h3>
<p>Heroku recommends adding a Procfile to your app. For simplicity, there’s no need to create a Procfile if you use Thin. If you declare the Thin gem in your Gemfile, Heroku sets up an appropriate web process without requiring a Procfile.</p>
<p>Procfile is a mechanism for declaring what commands are run when your web app runs on the Heroku platform. Heroku recommends it for greater control and flexibility over your app. If you add a Procfile, you can specify Thin as your web process in the Procfile.</p>
<h2>Precompile Assets</h2>
<p>Rails 3.1 introduced the asset pipeline which enables proper organization of <span class="caps">CSS</span> and JavaScript. Assets must be available as Javascript and <span class="caps">CSS</span> files when anyone visits your website. That means multiple files in various formats (CoffeeScript, <span class="caps">SASS</span>, etc.) must be compiled to simple Javascript and <span class="caps">CSS</span> files. During development, assets are compiled on the fly so you can easily make changes and see the results.</p>
<p>For deployment on Heroku, you have three options:</p>
<ul>
<li>do nothing and allow Heroku to attempt to precompile assets when you deploy to Heroku (slug compilation)</li>
<li>do nothing and allow Heroku to attempt to compile assets when the app is generated (runtime compilation)</li>
<li>precompile the assets before deployment to Heroku</li>
</ul><p>While runtime asset compilation will work, it should be used as a last resort. Using runtime compilation will require Rails to compile your assets each time a dyno boots up increasing the wait time for a new dyno to become available. If you do nothing and rely on Heroku to perform slug compilation (when you deploy to Heroku), you may find Heroku is unable to compile the assets and will default to runtime compilation. It’s best to precompile the assets before deployment to Heroku.</p>
<p>Heroku doesn’t check files in the <strong>config/initializers</strong> folder before attempting to precompile assets. That’s fine if you precompile assets before deploying to Heroku. Or if you don’t use the initializer files to set constants that are used in the assets files. You can avoid these issues by adding this configuration parameter to the <strong>config/application.rb</strong> file:</p>
<pre>
# Heroku requires this to be false
config.assets.initialize_on_precompile=false
</pre>
<p>To precompile assets before deployment to Heroku:</p>
<pre>
rake assets:precompile
</pre>
<p>See the article <a href="https://devcenter.heroku.com/articles/rails3x-asset-pipeline-cedar">Rails 3.1+ Asset Pipeline on Heroku Cedar.</a>.</p>
<h2>Commit to Git</h2>
<p>Your application must be committed to a Git repository before you can use Heroku. See <a href="http://railsapps.github.com/rails-git.html">Git and Rails</a> to learn how to set up Git for your application.</p>
<p>Store the modified application in the Git repository:</p>
<p><code>$ git commit -am "Configured for deployment to Heroku"</code></p>
<h2>Heroku Account</h2>
<p>To deploy an app to Heroku, you must have a Heroku account. Visit <a href="http://heroku.com/">http://heroku.com/</a> to set up an account. Heroku will ask you for your email address; it’s advisable to use the same email address you use for your GitHub account (see the article <a href="http://railsapps.github.com/rails-git.html">Git and Rails</a>).</p>
<h3>Using a Client’s Account</h3>
<p>You may want to deploy an app to an account that belongs to someone other than yourself (for example, your employer or a client). If you are using a client’s or employer’s Heroku account, you won’t be able to push your application to Heroku until you’ve added yourself as a collaborator. After you create an app on Heroku, log in to your client’s account on Heroku. Under “My Apps” you’ll see the name of the app you’ve created; click “General Info” and you’ll find a form where you can add yourself as a collaborator.</p>
<h3>Deploying for Multiple Accounts</h3>
<p>David Dollar’s <a href="https://github.com/ddollar/heroku-accounts">heroku-accounts plugin</a> will help if you must use multiple accounts on Heroku. With the heroku-accounts plugin, you can configure each application to deploy to the appropriate account.</p>
<p>To install the heroku-accounts plugin:</p>
<pre>
heroku plugins:install git://github.com/ddollar/heroku-accounts.git
</pre>
<p>To add an account locally (which you’ll call “work”):</p>
<pre>
$ heroku accounts:add work --auto
</pre>
<p>To list accounts that are set up locally:</p>
<pre>
$ heroku accounts
</pre>
<p>To set an account to use for a project:</p>
<pre>
# in project root
heroku accounts:set work
</pre>
<h2>Create Your Application on Heroku</h2>
<p>Use the Heroku create command to create and name your new app.</p>
<p><code>$ heroku create myapp</code></p>
<p>Replace <code>myapp</code> with something unique. Heroku demands a unique name for every hosted application. If it is not unique, you’ll see an error, “name is already taken.”</p>
<p>As of June 20, 2012, Heroku’s <a href="http://blog.heroku.com/archives/2012/5/24/cedar_goes_ga">default stack changed to Cedar</a>. Before, you needed to specify <code>$ heroku create myapp --stack cedar</code>; that’s no longer necessary.</p>
<p>If you don’t specify your app name (<code>myapp</code> in the example above), Heroku will supply a placeholder name. You can easily change Heroku’s placeholder name to a name of your choice with the <code>heroku apps:rename command</code> (see <a href="https://devcenter.heroku.com/articles/renaming-apps">Renaming Apps from the <span class="caps">CLI</span></a>).</p>
<p>Don’t worry too much about getting the “perfect name” for your Heroku app. The name of your Heroku app won’t matter if you plan to set up your Heroku app to use your own domain name. You’ll just use the name for access to the instance of your app running on the Heroku servers; later, you’ll set up <span class="caps">DNS</span> to point your domain name to the app running on Heroku.</p>
<h3>Set Heroku Environment Variables</h3>
<p>Your application may be obtaining usernames, passwords, or <span class="caps">API</span> keys for external services from the Unix shell environment. It’s a recommended practice to avoid recording sensitive information in your application code where it might be exposed publicly on a GitHub repo.</p>
<p>After create the Heroku app, you may need to set Heroku environment variables to provide the same data your application obtains from your local shell environment.</p>
<p>For example, for Gmail:</p>
<pre>
$ heroku config:add GMAIL_USERNAME=myname@gmail.com GMAIL_PASSWORD=secret
</pre>
<h3>Check Heroku Configuration</h3>
<p>You can check that everything has been added correctly by running:</p>
<p><code>$ heroku info --app myapp</code></p>
<h2>Using MongoDB</h2>
<p>If you are using MongoDB, you can use a Heroku add-on to deploy your app using the MongoHQ service. See <a href="http://addons.heroku.com/mongohq">details about the service</a> and <a href="http://devcenter.heroku.com/articles/mongohq">details about installation</a>.</p>
<p>To use MongoDB with your app, enable the add-on with the following command:</p>
<p><code>$ heroku addons:add mongohq:free</code></p>
<h4>Troubleshooting Problems Connecting to MongoHQ</h4>
<p>If you deploy your app and get the error message “failed to connect to any given host:port” or “Failed to connect to a master node at localhost:27017”, the <strong>config/mongoid.yml</strong> file may not have the correct MongoHQ connection parameters.</p>
<h2>Push Your Application to Heroku</h2>
<p>Push your application to Heroku:</p>
<p><code>$ git push heroku master</code></p>
<p>Review the output carefully. If you precompiled assets before deploying, you should see:</p>
<pre>
-&gt; Preparing app for Rails asset pipeline
   Detected manifest.yml, assuming assets were compiled locally
</pre>
<p><em>Note:</em> If you are using a client’s or employer’s Heroku account, you won’t be able to push your application to Heroku until you’ve added yourself as a collaborator. After you create the app on Heroku, log in to your client’s account on Heroku. Under “My Apps” you’ll see the name of the app you’ve created; click “General Info” and you’ll find a form where you can add yourself as a collaborator.</p>
<h4>Database Migrations</h4>
<p>You’ll need to run your database migrations (not applicable if you are using MongoDB):</p>
<p><code>$ heroku run rake db:migrate</code></p>
<p>Initialize your application database if your application requires it:</p>
<p><code>$ heroku run rake db:seed</code></p>
<p>These two commands can be combined as:</p>
<p><code>$ heroku run rake db:setup</code></p>
<h4>PostgreSQL Database Reset</h4>
<p>Heroku doesn’t support <code>rake db:reset</code>.</p>
<p>Need to reset your Heroku PostgreSQL database? Here’s how:</p>
<p><code>$ heroku pg:reset SHARED_DATABASE --confirm myapp</code></p>
<p>Don’t forget to restart your application or you won’t see any changes:</p>
<p><code>$ heroku restart</code></p>
<h2>Visit Your Site</h2>
<p>Open your Heroku site in your default web browser:</p>
<p><code>$ heroku open</code></p>
<p>Your app will be running at <a href="http://my-app-name.herokuapp.com/">http://my-app-name.herokuapp.com/</a>.</p>
<h2>Enabling Email</h2>
<p>Unless you enable email on Heroku, you’ll get errors when your application tries to send email from Heroku.</p>
<p>Heroku offers several options for sending email from your Rails application. See Heroku’s documentation <a href="http://devcenter.heroku.com/articles/smtp">Sending Email from Your App</a>.</p>
<h3>Email Service Providers</h3>
<p>For a production application, you’ll need to use an email service provider for your transactional email such as <a href="http://sendgrid.com/pricing.html">SendGrid</a> or <a href="http://mandrill.com/">Mandrill</a>.</p>
<h3>Gmail</h3>
<p>If you’re sending test emails during development, Gmail is the easiest option.</p>
<p>To use Gmail from Heroku, add the following to your <em>config/environments/production.rb</em> file:</p>
<pre>
config.action_mailer.default_url_options = { :host =&gt; 'myapp.herokuapp.com' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = false
config.action_mailer.default :charset =&gt; "utf-8"
config.action_mailer.smtp_settings = {
  address: "smtp.gmail.com",
  port: 587,
  domain: "myapp.herokuapp.com",
  authentication: "plain",
  enable_starttls_auto: true,
  user_name: ENV["GMAIL_USERNAME"],
  password: ENV["GMAIL_PASSWORD"]
}
</pre>
<p>To avoid storing your Gmail username and password in your Git repository, use environment variables to pass the username and password to your application. See Heroku’s documentation <a href="http://devcenter.heroku.com/articles/config-vars">Configuration and Config Vars</a>.</p>
<p>Set your Gmail username and password as Heroku environment variables:</p>
<pre>
$ heroku config:add GMAIL_USERNAME=no-reply@example.com GMAIL_PASSWORD=please
</pre>
<h2>Your Own Domain</h2>
<p>You’ll likely want to use your own domain name for your app.</p>
<p>See <a href="https://devcenter.heroku.com/articles/custom-domains">Heroku’s article about custom domains</a> for instructions.</p>
<h3>Why “www” Matters</h3>
<p>For simplicity, you might want your web app running on a “bare domain” like <a href="http://example.com/">http://example.com/</a>. You can do it, but Heroku explains <a href="https://devcenter.heroku.com/articles/avoiding-naked-domains-dns-arecords">Why You Should Avoid Naked Domains</a> and always use a <a href="http://en.wikipedia.org/wiki/Fully_qualified_domain_name">fully qualified domain name</a> such as <a href="http://www.example.com/">http://www.example.com/</a>.</p>
<h3>Set Your Domain Name</h3>
<p>This command tells Heroku that your app should respond to requests to “www.mydomain.com”:</p>
<pre>
$ heroku domains:add www.mydomain.com
</pre>
<h3>Set a <span class="caps">DNS</span> Record</h3>
<p>Domain Name Service (<a href="http://en.wikipedia.org/wiki/Domain_Name_System"><span class="caps">DNS</span></a>) routes requests for your domain to the servers that host your application. Your name service may be provided by your domain registrar (for example, GoDaddy) or a managed <span class="caps">DNS</span> provider (for example, <a href="https://dnsimple.com/">DNSimple</a> or <a href="http://www.zerigo.com/managed-dns">Zerigo</a>). You must visit your <span class="caps">DNS</span> provider’s website to set a <span class="caps">CNAME</span> record to route requests for “http://www.mydomain.com/” to your app running on Heroku.</p>
<p>Each <span class="caps">DNS</span> provider has a different interface for managing <span class="caps">DNS</span> records. This article doesn’t show you how to set a <span class="caps">CNAME</span> record.</p>
<p>After you have set a <span class="caps">CNAME</span> record, as soon as <span class="caps">DNS</span> records propagate (usually a few minutes but sometimes longer), your app should be running at <a href="http://www.mydomain.com/">http://www.mydomain.com/</a>.</p>
<h3>Using Subdomains</h3>
<p>You’ll need to enable “wildcard domains” if you want your application to accommodate arbitrary subdomains (for example, a different subdomain for each user account),</p>
<pre>
$ heroku domains:add *.mydomain.com
</pre>
<p>Then, visit your <span class="caps">DNS</span> provider to set a <span class="caps">CNAME</span> record to point “*.example.com” at “myapp.herokuapp.com”.</p>
<h3>Checking Subdomains</h3>
<p>You can check that everything has been added correctly by running:</p>
<pre>
$ heroku info --app myapp
</pre>
<p>As soon as <span class="caps">DNS</span> has propagated, your local computer will show that the domain name resolves properly:</p>
<pre>
$ host www.example.com
www.example.com has address ...
</pre>
<h2>Troubleshooting</h2>
<p>When you get errors, troubleshoot by reviewing the log files:</p>
<pre>
$ heroku logs
</pre>
<p>If necessary, use the Unix tail flag to monitor your log files. Open a new terminal window and enter:</p>
<pre>
$ heroku logs -t
</pre>
<p>to watch the server logs in real time.</p>
<h4>Where to Get Help</h4>
<p>Your best source for help with Heroku is <a href="http://stackoverflow.com/questions/tagged/heroku">Stack Overflow</a>. Your issue may have been encountered and addressed by others.</p>
<p>You can also check the <a href="http://devcenter.heroku.com/">Heroku Dev Center</a> or the <a href="http://groups.google.com/group/heroku/">Heroku Google Group</a>.</p>
    </div><!-- class="content" -->
    
    <div class="comments">
      <div class="content wikistyle gollum">
        <h2>Comments and Issues</h2>
      </div>
      <p>Is this helpful? Please add a comment below. Your encouragement fuels the project.</p>
      <p>Did you find an error? Or couldn't get something to work? For the example apps and tutorials, please create a GitHub issue in the repository for the example app. Creating a GitHub issue is the best way to make sure a problem is investigated and fixed.</p>
      <div id="disqus_thread"></div>
      <script type="text/javascript">
          /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
          var disqus_shortname = 'railsapps'; // required: replace example with your forum shortname
          /* * * DON'T EDIT BELOW THIS LINE * * */
          (function() {
              var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
              dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
              (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
          })();
      </script>
      <noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
      <a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>
    </div><!-- class="comments" -->

    <div class="footer row">
      <div class="span4">
        <h3>Credits</h3>
        <p><a href="http://danielkehoe.com/">Daniel Kehoe</a> initiated the <a href="http://railsapps.github.com/">RailsApps Project</a>. Thanks to all the users and contributors.</p>
      </div>
    
      <div class="span4">
        <h3>Wiki</h3>
        <p>Corrections? Additions? You can edit this page <a href="https://github.com/RailsApps/railsapps.github.com/wiki/_pages">on the wiki</a>.</p>
      </div>

      <div class="span4">
        <h3>Last edit</h3>
        <p>by <b>Daniel Kehoe</b>, 2012-07-20 23:08:42</p>
      </div>
    </div>

  </div>
            
  </body>
</html>
Something went wrong with that request. Please try again.