Create

Go to your project's root folder, which I will assume is version controlled with Git.

The basic command to create a Heroku application is just:

heroku create

Which creates a heroku remote in git:

git remote -v

However you may want to specify further by optionally adding:

Heroku Stack

heroku create -s cedar

At the moment it is unnecessary as the previous stack is not an option and a new one has not been announced.

Specify App name

heroku create foobar

Heroku then creates foobar.herokuapp.com instead of their random but cute naming strategies.

Staging (Multiple remotes)

A very handy option is the ability to specify remote names.
This allows you to have multiple application running on Heroku for the same project.
Which is then very handy if you want a staging server to test your project
on before deploying to your live instance.

heroku create --remote foobar

You can see your git remotes now have a foobar remote and not a heroku one:

git remote -v

As a consequence all heroku commands for this instance will need
to be appended with, e.g.

All options together

Which means I have to subsequently consciously specify which remote I want a heroku command to run against.
However for smaller project or at the start of project I only run with the default options.

Configure

You can configure your application easily, which allows nice external configuration. You don't however have an external configuration file, but instead use environment variables.

The environment variables may be urls, paths, passwords etc. A number of add-ons will automatically add entries for your application to use them.

To see which environment variables is currently set for your application:

heroku config

To add a varible:

heroku config:set FOO=bar

This will add a variable of FOO with the value bar.

heroku config

To remove a variable:

heroku config:unset FOO

Variable FOO now no longer exist.

heroku config

Play framework configuration example

In my Play & Heroku howto I show how I involve a Heroku only configuration file inside the application, and then in the Procfile I specify the path to this file. The configuration file then pulls the environment variable if present into the application using Typesafe config properties.

Add-ons

Heroku comes with a number very usefull add-ons.
They are extremely easily integrated, and all offer a free tier.

Custom domains

The custom domains add-on lets you specify alternative domain name for your application. The default foobar.herokuapp.com might be good, but you can also let the application respond to www.foobar.com if you prefer.

The custom domains add-on is lately included by default with all instances so you will not need to add the add-on itself anymore.

Deploy to Heroku

Deploying to Heroku is very simple. It is simply a git push:

git push heroku master

If you have used multiple Heroku remotes:

git push foobar master

This will push the latest source code to Heroku.
Heroku will try to establish wich language/framework to use,
the presence of a Procfile will ensure it guesses correctly.
It will then compile and if successful start your application.

When deployed ssuccessfullyand your application has started, you can quickly open your browser with:

heroku open

Logging

You have full access to the application log via

heroku logs

To continuously tail the log:

heroku logs -t

As there are often typos, misunderstanding etc that brake a deployment, (hence why I use staging environments first), I often quickly tail the log straight away after a deployment.

git push heroku master && heroku logs -t

And when the logs indicate the app is up and running again I run:

heroku open && heroku logs -t

Scale and restarts

To find out how many dynos are running:

heroku ps

To scale up or down:

heroku ps:scale web=1

Restart

If you application has crashed, but you fixed the problem without needing a redeploy you can restart the application node with: