> ## Documentation Index
> Fetch the complete documentation index at: https://docs.shardcloud.app/llms.txt
> Use this file to discover all available pages before exploring further.

# How to Migrate from Heroku to Shard Cloud

> Move a Heroku app (code, config vars, Postgres, workers and scheduled jobs) to Shard Cloud, step by step.

## Introduction

This guide moves a Heroku app to Shard Cloud. Every part of a Heroku app has a direct counterpart:

| On Heroku | On Shard Cloud |
| - | - |
| `web` dyno | An [application](https://docs.shardcloud.app/apps.md) with a `SUBDOMAIN` |
| `worker` dyno (or any other Procfile process) | Another application, without a subdomain |
| `release` phase | A command that runs before your app starts |
| Config vars | Environment variables (import a `.env` file) |
| Heroku Postgres | A PostgreSQL [database](https://docs.shardcloud.app/databases.md) |
| Heroku Redis | A Redis database |
| Heroku Scheduler | A small application that runs the jobs on a timer |
| Buildpacks | Shard Cloud's language containers install your dependencies |
| Custom domain + ACM | [Custom domain](https://docs.shardcloud.app/tutorials/platform/custom-domain.md), with HTTPS included |

Things that get simpler:

* **`$PORT` keeps working.** Every Shard Cloud container sets `PORT=80`, so an app that listens on `process.env.PORT` (or `os.environ["PORT"]`) needs no change. It must listen on `0.0.0.0`, as on Heroku.
* **The disk is persistent.** Unlike Heroku's ephemeral filesystem, files your app writes under `/app` survive restarts (up to the [storage limit](https://docs.shardcloud.app/limits.md)).
* **No dyno sleeping.** Apps run all the time and restart automatically if they crash.

## Before You Start

### What you need

* The [Heroku CLI](https://devcenter.heroku.com/articles/heroku-cli), logged in to the account that owns the app
* The app's code (`git clone` of your repository, or `heroku git:clone -a YOUR_APP`)
* A Shard Cloud account. Each Procfile process becomes an application, and each add-on database a database, so check that their RAM fits in your plan (see the minimums on the [limits page](https://docs.shardcloud.app/limits.md))
* To restore the database: [Docker](https://www.docker.com/), or `pg_restore` installed locally

### Take stock of the app

Run these from the code folder, replacing `YOUR_APP`:

```bash theme={null}
cat Procfile                      # the processes to recreate
heroku addons -a YOUR_APP         # databases, Redis, Scheduler...
heroku pg:info -a YOUR_APP        # the Postgres version ("PG Version")
heroku buildpacks -a YOUR_APP     # the language
```

## Step 1: Export the Config Vars

```bash theme={null}
heroku config --shell -a YOUR_APP > heroku.env
```

`heroku.env` now holds every config var as `KEY=value`. Open it and:

* **Delete the ones the add-ons manage**, such as `DATABASE_URL`, `HEROKU_POSTGRESQL_*`, `REDIS_URL` and `REDIS_TLS_URL`: you'll set them to the new databases in step 4.
* Leave everything else as it is.

> [!WARNING]
>
> `heroku.env` contains your secrets. Don't commit it, and delete it when you're done.

## Step 2: Create the Databases

**1. PostgreSQL**

In the [Dashboard](https://shardcloud.app/dash), create a **PostgreSQL** database. Pick the same major version as Heroku's (`heroku pg:info`) or a newer one: the version can't change later. Give it at least as much room as the data needs (database storage grows with RAM, see [limits](https://docs.shardcloud.app/limits.md)).

**2. Redis (if you use Heroku Redis)**

Create a **Redis** database. Heroku Redis is usually a cache or a job queue, so it starts empty: there's nothing to copy.

**3. Copy the connection URLs**

Each database's page shows its connection URL. You'll use them in steps 3 and 4.

## Step 3: Move the Postgres Data

> [!TIP]
>
> To keep the data consistent, put the Heroku app in maintenance mode first: `heroku maintenance:on -a YOUR_APP`. Writes made after the backup won't be copied.

Capture a fresh backup and download it:

```bash theme={null}
heroku pg:backups:capture -a YOUR_APP
heroku pg:backups:download -a YOUR_APP    # saves latest.dump
```

Restore it into the Shard Cloud database. Use a `pg_restore` of your Shard Cloud database's major version, for example with Docker (`postgres:17` for a PostgreSQL 17 database):

```bash theme={null}
docker run --rm -v "$PWD:/backup" postgres:17 \
  pg_restore --verbose --no-owner --no-acl \
  --dbname "YOUR_SHARD_CLOUD_DATABASE_URL" /backup/latest.dump
```

Or, with `pg_restore` installed locally:

```bash theme={null}
pg_restore --verbose --no-owner --no-acl --dbname "YOUR_SHARD_CLOUD_DATABASE_URL" latest.dump
```

`--no-owner --no-acl` drops Heroku's roles and grants, which don't exist on Shard Cloud. `pg_restore` may report errors about Heroku-specific objects (such as the `heroku_ext` schema or an extension that isn't available); check that your tables and their row counts are all there:

```bash theme={null}
psql "YOUR_SHARD_CLOUD_DATABASE_URL" -c "\dt+"
```

> [accordion] MySQL (JawsDB, ClearDB)
>
> Create a **MySQL** database, then copy the data with `mysqldump` and the `mysql` client:
>
> ```bash theme={null}
> mysqldump --single-transaction --routines --triggers -h OLD_HOST -u OLD_USER -p OLD_DB > dump.sql
> mysql -h NEW_HOST -P NEW_PORT -u NEW_USER -p NEW_DB < dump.sql
> ```
>
> Take the old values from the add-on's URL (`heroku config:get JAWSDB_URL -a YOUR_APP`) and the new ones from the database page.

> [accordion] MongoDB
>
> Create a **MongoDB** database, then copy the data with the MongoDB Database Tools:
>
> ```bash theme={null}
> mongodump --uri "OLD_MONGODB_URL" --archive=dump.archive --gzip
> mongorestore --uri "YOUR_SHARD_CLOUD_MONGODB_URL" --archive=dump.archive --gzip
> ```

## Step 4: Set the Environment Variables

Add the new databases' URLs to `heroku.env`, under the names your code reads:

```bash heroku.env theme={null}
DATABASE_URL=YOUR_SHARD_CLOUD_DATABASE_URL
REDIS_URL=YOUR_SHARD_CLOUD_REDIS_URL
```

You'll import this file into each application in step 6.

> [!NOTE]
>
> Heroku Postgres requires SSL, so many apps already connect with `ssl: { rejectUnauthorized: false }` (Node) or `sslmode=require`. That keeps working: Shard Cloud databases only accept encrypted connections. To verify the certificate instead, see [Verifying the Certificate](https://docs.shardcloud.app/databases.md#verifying-the-certificate).

## Step 5: Translate the Procfile

Each line of the `Procfile` becomes one application, configured by a [`.shardcloud`](https://docs.shardcloud.app/config) file. The start command goes in `CUSTOM_COMMAND`, and a `release` command goes in front of the `web` command, so it runs each time the app starts.

Heroku runs your build (`npm run build`, `collectstatic`...) during the deploy. Shard Cloud installs the dependencies but doesn't run a build, so put the build in the start command too.

> [tab] Node.js
>
> ```text Procfile theme={null}
> release: npx prisma migrate deploy
> web: npm start
> worker: node worker.js
> ```
>
> becomes, for the web process:
>
> ```systemd .shardcloud theme={null}
> DISPLAY_NAME=My App
> LANGUAGE=node
> MEMORY=512
> VERSION=recommended
> SUBDOMAIN=myapp
> CUSTOM_COMMAND=npx prisma migrate deploy && npm run build && npm start
> ```
>
> Drop `npm run build` if your `package.json` has no `build` script. Dependencies are installed with npm, yarn, pnpm or bun, following your lockfile. Set `VERSION` to the Node.js major version in your `engines` field if it isn't the recommended one.

> [tab] Python
>
> ```text Procfile theme={null}
> release: python manage.py migrate
> web: gunicorn myproject.wsgi
> worker: celery -A myproject worker
> ```
>
> becomes, for the web process:
>
> ```systemd .shardcloud theme={null}
> DISPLAY_NAME=My App
> LANGUAGE=python
> MEMORY=512
> VERSION=recommended
> SUBDOMAIN=myapp
> CUSTOM_COMMAND=python manage.py migrate && python manage.py collectstatic --noinput && python -m gunicorn myproject.wsgi
> ```
>
> > [!WARNING]
> >
> > Run Python tools as modules: `python -m gunicorn`, `python -m celery`, `python -m uvicorn`. Packages from `requirements.txt` are installed where Python finds them, but their command-line scripts aren't on the `PATH`, so a bare `gunicorn` isn't found.
>
> Gunicorn listens on `0.0.0.0:$PORT` by itself. For Django, add your Shard Cloud address to the settings:
>
> ```python settings.py theme={null}
> ALLOWED_HOSTS = [".shardweb.app", "yourdomain.com"]
> CSRF_TRUSTED_ORIGINS = ["https://myapp.shardweb.app", "https://yourdomain.com"]
> ```
>
> Set `VERSION` to the Python version of your `.python-version` or `runtime.txt` if it isn't the recommended one.

> [tab] Other languages
>
> The same rules apply: the `web` command goes in `CUSTOM_COMMAND`, the app listens on `$PORT` (80), and each extra process is its own application. See the guide for your language: [Ruby](https://docs.shardcloud.app/languages/ruby.md), [Go](https://docs.shardcloud.app/languages/go.md), [PHP](https://docs.shardcloud.app/languages/php.md), [Java](https://docs.shardcloud.app/languages/java.md), [Elixir](https://docs.shardcloud.app/languages/elixir.md) or [C#](https://docs.shardcloud.app/languages/csharp.md). For Rails, see the [Rails tutorial](https://docs.shardcloud.app/tutorials/website/rails.md).

### Workers and other processes

A `worker` (or any process that doesn't receive web traffic) is an application **without** `SUBDOMAIN`, so it needs only 256 MB:

```systemd .shardcloud theme={null}
DISPLAY_NAME=My App Worker
LANGUAGE=node
MEMORY=256
VERSION=recommended
CUSTOM_COMMAND=node worker.js
```

Give it the same environment variables as the web app. Run the `release` command in the web app only.

### Heroku Scheduler

Shard Cloud has no job scheduler of its own. Run the jobs from a small application instead (or from your worker), with a scheduling library such as [node-cron](https://www.npmjs.com/package/node-cron) for Node.js or [APScheduler](https://apscheduler.readthedocs.io/) for Python:

```javascript scheduler.js theme={null}
const cron = require('node-cron');
const { execSync } = require('child_process');

// Every day at 03:00 UTC: the same command you had in Heroku Scheduler
cron.schedule('0 3 * * *', () => {
  execSync('node scripts/cleanup.js', { stdio: 'inherit' });
}, { timezone: 'UTC' });
```

Since applications restart automatically, the scheduler comes back by itself if it crashes.

## Step 6: Deploy

**1. Upload the web app**

Add the web app's `.shardcloud` to the root of your code, zip it **without** `node_modules/`, virtualenvs or build output (100 MB at most), and upload it in the [Dashboard](https://shardcloud.app/dash/applications).

**2. Import the environment variables**

On the application's page, open **Environment Variables**, choose **Import .env** and pick `heroku.env`. Check the values, then restart the application.

**3. Repeat for each other process**

Upload the same code with that process's `.shardcloud` (no `SUBDOMAIN`), and import the same `heroku.env`.

**4. Connect GitHub (optional)**

To deploy on every push, like Heroku's GitHub integration, connect each application to your repository on its **Deploy** page. See [Git integration](https://docs.shardcloud.app/tutorials/platform/git-integration.md).

> [!WARNING]
>
> A `.shardcloud` file in your repository is applied to **every** application deployed from it. With a web app and a worker on the same repository, keep `.shardcloud` out of the repository (add it to `.gitignore`) and let each application keep the one it was uploaded with.

## Step 7: Test, Then Switch the Domain

**1. Test on the free subdomain**

Open `https://myapp.shardweb.app`, log in, and check pages that read and write data. Check the workers' logs on their pages.

**2. Add your domain**

Add your domain to the web app and point its DNS at Shard Cloud, replacing the Heroku DNS target. See [Custom Domain](https://docs.shardcloud.app/tutorials/platform/custom-domain.md). HTTPS is set up for you.

**3. Shut down Heroku**

Once traffic is on Shard Cloud and you've checked the data, scale the Heroku dynos to zero (`heroku ps:scale web=0 worker=0 -a YOUR_APP`). Keep the Heroku database until you're sure nothing is missing, then remove the add-ons to stop the charges.

## Troubleshooting

> [accordion] The app starts but the site doesn't load
>
> The server must listen on `0.0.0.0` and on `$PORT` (80). A hardcoded port such as 3000 or 5000, or listening on `localhost` only, makes the site unreachable.

> [accordion] gunicorn: not found (or celery, uvicorn)
>
> Use `python -m gunicorn` (or `python -m celery`, `python -m uvicorn`) in `CUSTOM_COMMAND`.

> [accordion] Out of memory during the build
>
> The build runs when the app starts, inside the app's RAM. Raise `MEMORY` (1024 MB is a safe start for frontend builds) or build locally and upload the built files.

> [accordion] pg\_restore: unsupported version in file header
>
> The `pg_restore` you used is older than Heroku's Postgres. Use a newer one, for example the `postgres:17` or `postgres:18` Docker image.

> [accordion] Changed an environment variable and nothing happened
>
> Environment variables are read when the app starts: restart the application after changing them.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.