Installing a Free SSL Certificate on Heroku

Update - 3/21

Heroku now does this automagically.


Installing Certbot

Certbot is a command line application for automatically generating SSL certificates from Let's Encrypt. If you weren't using Heroku you would run this on your server to generate the certificates. Since we don't operate the system on Heroku, we'll generate the certificates locally and then upload them to Heroku.

If you have Homebrew on OSX you can simply run:

brew install certbot

If not, you can get the software at the Certbot homepage.

Generating an SSL Certificate

With Certbot installed we can now go ahead and generate our free certificate. From the command line you'll want to run:

sudo certbot certonly --manual

It will then ask for you to enter in your domain name. If you're using a domain prefix like "www", make sure you include that as well. For example:

From there it will ask if its OK that your IP is logged and then give instructions on how to verify you own the domain. Do not continue until you read and setup the verification.

It will provide a path and ask you to render text at that path.

Make sure your web server displays the following content at before continuing:


The first part is the path. This is where Certbot is going to check for the key listed below. In other words we have to make sure that when Certbot visits the path, the below key is displayed as text.

For example, if you're using Rails, you can create the file in your ./public directory or create a controller and route to render the text.

In ./config/routes.rb you can add:

get '/.well-known/acme-challenge/:id' => 'index#letsencrypt'

And then create and add the following to the Index controller:

class IndexController < ApplicationController
  def letsencrypt
    render text: "zzzzzzzzzzzzzzzzzz-xxxxxxxxxxxxxxxxxxxxxxxx.yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"

Make sure you then push the changes to Heroku. You can test that this works by visiting the path listed above in your web browser:

You should see the code. Once that's working, go ahead an continue with the Certbot install.

Uploading Your Certificate to Heroku

If Certbot verified your domain correctly, you should see the following message:

 - Congratulations! Your certificate and chain have been saved at
   /etc/letsencrypt/live/ Your
   cert will expire on 2017-06-08. To obtain a new or tweaked version
   of this certificate in the future, simply run certbot again. To
   non-interactively renew *all* of your certificates, run "certbot

This will give us the location of your certificate. You can verify this by running:

sudo ls /etc/letsencrypt/live/

Note: We have to use sudo here because certbot creates protected folders. We cannot access the folder with out admin priviledges therefore we use sudo.

You should see something like:


If that looks good, go ahead and add the certificate to Heroku:

sudo heroku certs:add /etc/letsencrypt/live/ /etc/letsencrypt/live/

Once again, we're using sudo to access the protected files. If all went well, you should now be able to see your new certificate in action, by going to:

in your browser!