# Heroku Deploy

We currently use Heroku for deploying to production but LightningRails works with other popular options as well. We will add a guide to other ones very soon.

To install Heroku CLI in your terminal, follow these instructions:

### macOS installation <a href="#macos-installation" id="macos-installation"></a>

```bash
brew tap heroku/brew && brew install heroku
heroku --version # It should display heroku/x.x.x
```

⚠️ If you get this error:

```bash
Bad CPU type in executable
```

Execute this command:

```bash
softwareupdate --install-rosetta --agree-to-license
heroku --version # Now it should display heroku/x.x.x
```

### Ubuntu installation <a href="#ubuntu-installation" id="ubuntu-installation"></a>

```bash
curl https://cli-assets.heroku.com/install.sh | sh
heroku --version # It should display heroku/x.x.x
```

### Login <a href="#login" id="login"></a>

Signin from the terminal to be able to push directly from the terminal

```bash
heroku login
```

### Create your heroku app

To create an app and automatically connect it to your current directory of code through the GitHub remotes:

```bash
heroku create myawesomeapp --region eu
```

{% hint style="info" %}
It's important to set the correct region, otherwise your methods like Time.now will have the wrong time zone, plus you might get in trouble down the line with cookies and users data storage 🍪
{% endhint %}

### Push to production

After committing your last line of code, you can now push to production with a simple command

```bash
git push heroku master
```

### Migrate your database

Remember that your development database is only in your computer and stored locally, heroku in turn is in the cloud, which means it will have a different database, that you must migrate and seed.

```bash
heroku run rails db:migrate  # Run pending migrations in production
heroku run rails db:seed     # Run the seed in production
```

### Credential variables

Along the same lines as we set our API keys in our credentials file and .env file, you must set it to your production environment

```
heroku config:set postmark_api=YOUR_API_KEY
# repeat for all the API keys you have setup
```

### Stripe credentials

You will need to go to your stripe dashboard and toggle the "Live" button, to access the live api keys "developers" > API. Once done, copy the keys  in your terminal with the following command to&#x20;

```bash
heroku config:set STRIPE_PUBLIC_KEY=****
heroku config:set STRIPE_PRIVATE_KEY=****
```

You will also need to create a webhook under "Webhooks":

1. Click on "add an endpoint"
2. Add the endpoint url: *`"https://example.org/pay/webhooks/stripe"`*
3. Select events: Charge + checkout
4. Copy the key and paste it in your terminal with the following command

```bash
heroku config:set STRIPE_SIGNING_SECRET=*****

```

### Error Handling in Heroku

If you run into an error when opening your app in the browser with

```bash
heroku open
```

You will need to investigate by looking at the logs

```bash
heroku logs --tail
```
