# Deploy FusionAuth to Heroku

Learn how to deploy FusionAuth to Heroku with the FusionAuth Docker image and Heroku Postgres.

> For the index of this section of the site, see [llms.txt](https://fusionauth.io/docs/llms.txt)

You can run the FusionAuth Docker image on [Heroku](https://www.heroku.com/) with a Heroku Postgres database. The image needs a small wrapper on Heroku for the following reasons:

*   Heroku Postgres sets `DATABASE_URL` to a `postgres://` URL. FusionAuth reads the same variable, but expects a JDBC URL, with the username and password in separate variables.
*   Heroku assigns the HTTP port at runtime in the `PORT` variable. The web process must listen on that port.
*   Heroku ignores the `USER` in a Dockerfile and runs the container as a different non-root user. By default, that user can't write to the FusionAuth install directory.

## Prerequisites

*   A Heroku account with a payment method. Heroku Postgres and the dyno sizes that FusionAuth needs aren't free.
*   The [Heroku CLI](https://devcenter.heroku.com/articles/heroku-cli), logged in to your account.
*   Git.

Use a Cedar-generation app

Heroku builds Docker images from `heroku.yml` only in Cedar-generation apps. Fir-generation apps don't support Docker builds. Apps in the Common Runtime run on Cedar. For more information, see [Heroku Generations](https://devcenter.heroku.com/articles/generations).

## Create the Project

1.  Create a folder for the project:
    
    ```shell-session
    $ mkdir fusionauth-heroku
    $ cd fusionauth-heroku
    ```
    
2.  Create a file named `heroku-start.sh` with the following content:
    
    heroku-start.sh
    
    ```shell
    #!/bin/sh
    set -e
    # heroku sets DATABASE_URL to postgres://user:password@host:port/dbname
    url="${DATABASE_URL#*://}"
    export DATABASE_USERNAME="${url%%:*}"
    url="${url#*:}"
    export DATABASE_PASSWORD="${url%%@*}"
    export DATABASE_URL="jdbc:postgresql://${url#*@}?sslmode=require"
    export DATABASE_ROOT_USERNAME="$DATABASE_USERNAME"
    export DATABASE_ROOT_PASSWORD="$DATABASE_PASSWORD"
    # the heroku user may have no writable home directory
    export HOME=/usr/local/fusionauth
    exec env "fusionauth-app.http.port=$PORT" /usr/local/fusionauth/fusionauth-app/bin/start.sh
    ```
    
    The script reads `DATABASE_URL` at every start, because Heroku changes the URL when Heroku rotates the database credentials or fails over. The script adds `sslmode=require`, because Heroku Postgres accepts only SSL connections.
    
    The script also sets the Heroku database user as the root database user. FusionAuth then runs in [Silent Mode](https://fusionauth.io/docs/deploy/production/install/silent-mode.md), which creates the database schema on the first start and applies database migrations after an update.
    
3.  Create a file named `Dockerfile` with the following content:
    
    Dockerfile
    
    ```dockerfile
    FROM fusionauth/fusionauth-app:1.71.1
    USER root
    COPY heroku-start.sh /usr/local/fusionauth/heroku-start.sh
    # heroku ignores USER and runs the container as a different user
    RUN chmod -R a+rwX /usr/local/fusionauth /opt/openjdk/conf/security && chmod a+x /usr/local/fusionauth/heroku-start.sh
    USER fusionauth
    CMD ["/usr/local/fusionauth/heroku-start.sh"]
    ```
    
    The FusionAuth start script writes to the install directory and to the Java security directory, so the Dockerfile makes both directories writable for any user.
    
4.  Create a file named `heroku.yml` with the following content:
    
    heroku.yml
    
    ```yaml
    build:
      docker:
        web: Dockerfile
    ```
    
5.  Commit the files to a Git repository:
    
    ```shell-session
    $ git init
    $ git add .
    $ git commit -m "Deploy FusionAuth to Heroku"
    ```
    

## Deploy to Heroku

1.  Create a Heroku app that builds from Docker. Replace `<app-name>` with a name for the app:
    
    ```shell-session
    $ heroku create <app-name> --stack container
    ```
    
    The command also adds a Git remote named `heroku` to the repository.
    
2.  Add a Heroku Postgres database to the app:
    
    ```shell-session
    $ heroku addons:create heroku-postgresql:essential-0 --app <app-name>
    ```
    
    The `essential-0` plan is the smallest Heroku Postgres plan. For the other plans, see [Heroku Postgres Plans](https://devcenter.heroku.com/articles/heroku-postgres-plans).
    
3.  Set the FusionAuth configuration:
    
    ```shell-session
    $ heroku config:set SEARCH_TYPE=database FUSIONAUTH_APP_RUNTIME_MODE=production --app <app-name>
    ```
    
    `SEARCH_TYPE=database` uses the database for user search, so the app doesn't need Elasticsearch or OpenSearch. For more information, see [Search](https://fusionauth.io/docs/users/search.md).
    
4.  Push the repository to Heroku:
    
    ```shell-session
    $ git push heroku HEAD:main
    ```
    
    Heroku builds the image and starts a web dyno.
    
5.  Change the web dyno size to Standard-2X:
    
    ```shell-session
    $ heroku ps:type web=standard-2x --app <app-name>
    ```
    
    FusionAuth uses a 512 MB Java heap by default, and Basic and Standard-1X dynos have 512 MB of memory in total. A Standard-2X dyno has 1 GB. For the heap setting, see `fusionauth-app.memory` in [Configuration](https://fusionauth.io/docs/deploy/production/configuration.md).
    
6.  Open the app:
    
    ```shell-session
    $ heroku open --app <app-name>
    ```
    

## Confirm the Deployment

The app opens the FusionAuth setup wizard. Complete the setup wizard to create an admin user. For more information, see [First-Time Setup](https://fusionauth.io/docs/get-started/first-time-setup.md).

When the app doesn't load, read the logs:

```shell-session
$ heroku logs --tail --app <app-name>
```

The log line `HTTP server listening on port` shows that FusionAuth started and listens on the Heroku port.

## Proxy Headers

The Heroku router handles HTTPS and forwards requests to FusionAuth over HTTP. The router sets `X-Forwarded-Proto`, `X-Forwarded-Port`, and `X-Forwarded-For`, and keeps the original `Host` header. For more information, see [Proxy Setup](https://fusionauth.io/docs/deploy/production/proxy-setup.md).

## Update FusionAuth

To update FusionAuth, change the version in the `FROM` line of the `Dockerfile`. Commit the change, and push the repository to Heroku again. Silent Mode applies the database migrations when the new dyno starts.

FusionAuth applies the database migrations before FusionAuth listens on the Heroku port. Heroku restarts a web dyno that doesn't listen on the port within 60 seconds. When an update fails with an R10 error, see [Boot Timeout](https://devcenter.heroku.com/articles/limits#boot-timeout).

Related

[Deploy Microsoft Azure Kubernetes Service (AKS) Learn how to provision an AKS cluster in Microsoft Azure. dockercontainer](https://fusionauth.io/docs/deploy/production/kubernetes/aks.md)

[Deploy Elastic Kubernetes Service (EKS) Learn how to provision an EKS cluster in AWS. dockercontainer](https://fusionauth.io/docs/deploy/production/kubernetes/eks.md)

[Deploy Deploy with k8s Learn how to deploy FusionAuth in a Kubernetes Cluster. dockercontainer](https://fusionauth.io/docs/deploy/production/kubernetes/fusionauth-deployment.md)

[Deploy Google Kubernetes Engine (GKE) Learn how to provision a GKE cluster in Google Cloud (GCP). dockercontainer](https://fusionauth.io/docs/deploy/production/kubernetes/gke.md)
---

## Other pages in Marketplaces

> For the full index of this section, see [Deploy](https://fusionauth.io/docs/llms-deploy.txt).

- [AWS](https://fusionauth.io/docs/deploy/production/marketplaces/aws.md): Learn how to use FusionAuth with the AWS Marketplace.
- [DigitalOcean](https://fusionauth.io/docs/deploy/production/marketplaces/digitalocean.md): Learn how to use FusionAuth with the DigitalOcean Marketplace.
- [Google Cloud](https://fusionauth.io/docs/deploy/production/marketplaces/google-cloud.md): Learn how to use FusionAuth with the GCP Marketplace.
- [Install from a Marketplace](https://fusionauth.io/docs/deploy/production/marketplaces.md): Learn how to install FusionAuth using cloud marketplaces or templates.
- [Render](https://fusionauth.io/docs/deploy/production/marketplaces/render.md): Set FusionAuth up on Render from a Blueprint.
