---
# System prepended metadata

title: Generic Heroku Deploy Instructions

---

# Generic Heroku Deploy Instructions

When deploying to heroku there are three general phases:

1. **Local configuration** -- his step involves adding a `Procfile` and making any needed changes to your local repo to prep for deploy
1. **Creation of the the heroku app** -- For this step you need to create a heroku app and link it to your github repo and local repo
1. **Configuring the App** -- in this step you need to set your enviromental varaibles and do configure things like data migrations. You might need to redeploy your app several times and moniter the logs of your deployment to debug during this phase.

## Local Configuration

For this step you need to create a `Procfile` at the top level of your repo with the command to run your server in it preceeded but `web: `. For example `web: node .` tells heroku to run `node .` to run your server or `web: node ./bin/www`.

Some setups, such as django (see the Extra Resources section below), need more config at this stage. Django apps, for example, will need an alternative server installed, like `guninicorn` and modifacations made to the config.

Remember to `git add, commit and push` your changes when finished!

## Creation of the Heroku app

Navigate to heroku and make a new app. Find your github repo and connect it to your heorku app from the **deploy** tab.

Return to your terminal and use `heroku git:remote -a <your app name>` to connect your terminal to your app.

## Configuring the App

You will have some enviromental variables to configure at a minimum. For node projects, everything in the `.env` file should be added. Use `heroku config:set KEY=value` to set the varaibles. Once finished use `heroku config` to check the variables. **_NOTE_** if adding varaibles throws an error try putting the key in quotes: `heroku config:set KEY="value"`.

If you have a postgres db you will need to also add a database and run migrations.

* `heroku addons:create heroku-postgresql:mini` adds a postgres db to your deployment.
* `heroku run < your migration command >` will run migrate the database
* `heroku pg:psql` connects to your cloud db's `psql` shell to run raw SQL queries against it.
* `heroku run < your command >` can be used to exectue any script or configuration your might need

If you have errors during this process remember to:

* _monitor the build logs on heroku_ -- If it fails during this step you might want to take a look at the dependancies and how they are being installed.
* _monitor `heroku logs --tail`_ to see your server's output. Do you see your server starting up? Does making a request cause the bug?

Heroku has some specific errors you might see all of them are prefixed with an 'H' followed by a number, such a `H=10`. Google these errors if you see them to get to the bottom of the issue. 

## Extra Resources

* [django deploy instructions](https://github.com/ga-sei-lessons/620-django-deploy-test/blob/main/deploy_notes.md)
* [gitbook deploy instructions](https://gasei.gitbook.io/sei/00-config-deployment) (see sections on the )
* [convience link](https://console.cloud.google.com) google cloud dev console

###### tags: `lessons`

