- Home
- Rails hosting
- Move off Heroku
Guide
Moving a Rails app from Heroku to your own server
A Rails app on Heroku is already most of the way to running anywhere. Its code, config vars, and Postgres database are the whole move. Here's how to do it with a few minutes of downtime, whether you build the server yourself or let Hatchbox do it.
Most teams leave Heroku because of the bill: dynos and add-ons priced per app add up fast, and a $20–50 server can run what costs hundreds a month there. In February 2026, Heroku also moved the platform to sustaining engineering, and some teams don't want to wait to find out what that means for them.
Step 1: List what Heroku runs for you
Start with three commands. Save their output, because it's your checklist for the rest of the move.
heroku ps -a myapp # process types from your Procfile
heroku addons -a myapp # Postgres, Redis, Scheduler, logging, email...
heroku config -s -a myapp # config vars as NAME=value lines
Then map each piece to its replacement:
| On Heroku | On your own server | On Hatchbox |
|---|---|---|
| web dyno | Puma under systemd, behind Caddy or Nginx | Added on the first deploy |
| worker dyno | A systemd unit for Sidekiq or bin/jobs | Added when Sidekiq or Solid Queue is detected |
| release phase | Run migrations in your deploy script | db:migrate runs once per deploy; other one-off tasks go in .hatchbox/post-deploy |
| Heroku Postgres | Postgres from apt, or a managed database | Postgres on your server, or any managed DATABASE_URL |
| Heroku Redis | Redis from apt | Redis on your server |
| Heroku Scheduler | cron | Cron jobs in the dashboard |
| Automated certificate management | Caddy, or Nginx with certbot | Caddy, automatic |
| Email, logging, monitoring add-ons | Keep them: they're just config vars | Keep them: they're just config vars |
Heroku's filesystem is wiped on every restart, so uploads are already in S3 or similar. Nothing to move there: copy the storage credentials along with your other config vars.
Step 2: Set up the new server and deploy
Pick a server with at least as much memory as your dynos used, plus room for Postgres if it's moving onto the same machine. Two Standard-2X dynos (1GB each) and a small Postgres fit comfortably on a 4GB server.
Building it yourself: install Ruby, Postgres, Redis if you use Sidekiq, and Caddy or Nginx, and write a systemd unit for each process in your Procfile. Or use Kamal, Rails 8's Docker-based deploy tool. The Rails VPS deploy guide covers both.
With Hatchbox: connect your cloud account, create a server, create
an app from the same git repository, and attach a Postgres database. Hatchbox gives
the app its own hatchboxapp.com subdomain, so you can deploy and test it
before touching DNS.
Step 3: Copy your config vars
heroku config -s prints one NAME=value per line, the format
Hatchbox's bulk environment variable editor takes. Before you paste, remove the
variables the new server sets for itself:
DATABASE_URLandREDIS_URL, which should point at the new database and Redis- Anything starting with
HEROKU_, and the*_URLvariables of add-ons you're replacing PORT, which the server assigns
Look over values with spaces or special characters: the shell format can wrap them in quotes, which should come off when you paste into a form that doesn't expect them. Hatchbox's bulk editor replaces the app's variables with exactly what you save, so paste the whole list at once.
Step 4: Do a practice database copy
Copy the database once without stopping anything, so you know how long it takes and whether it restores cleanly. Download a backup from Heroku and copy it to the server:
heroku pg:backups:capture -a myapp
heroku pg:backups:download -a myapp # saves latest.dump
scp latest.dump deploy@your-server-ip:~/
Then restore it on the server into the new, empty database. Run
pg_restore as postgres and pass your app's database user to
--role, so that user owns everything it restores. Leave out
pg_stat_statements, which Heroku enables but only a superuser can create:
pg_restore -l < latest.dump | grep -v pg_stat_statements > restore.list
sudo -u postgres pg_restore --verbose --no-owner --no-acl \
--role=myapp_user -L restore.list -d myapp_production < latest.dump
--no-owner and --no-acl drop Heroku's role names, which don't
exist on your server. Reading the dump from standard input means the
postgres user doesn't need access to your home directory. Common
extensions like pgcrypto, citext, and pg_trgm
restore as your app's user. Ones that need a superuser, like PostGIS or pgvector, need
their apt package installed and the extension created as postgres
first. See
PostgreSQL extensions on Hatchbox.
Open the app on its test URL and click around before going further.
Step 5: Cut over
A day before, lower the TTL on your domain's DNS records to a few minutes. On the day, downtime lasts as long as one dump and restore:
- Run
heroku maintenance:on -a myappand scale workers to zero withheroku ps:scale worker=0 -a myapp, so nothing writes to the old database. - Empty the practice copy with
sudo -u postgres dropdb myapp_productionandsudo -u postgres createdb -O myapp_user myapp_production, then capture, download, and restore a fresh backup exactly as you practiced. - Deploy the app on the new server so migrations and processes start against the restored data.
- Add your domain to the new app, point its DNS at the new server, and wait for the SSL certificate. Caddy requests it once DNS resolves to the server.
- Watch logs and error tracking for a day. Keep the Heroku app and its database around, in maintenance mode, until you're sure.
Most apps with a database under a few gigabytes are down for 5–15 minutes. A larger database takes longer, or calls for streaming replication instead of a dump.
What changes after the move
You pay for a server, not dynos, so a second or third app on the same server adds nothing to the bill. You can SSH in, run a Rails console, and read logs directly. In exchange, backups, OS updates, and capacity are now your call. Hatchbox automates the first two. For a cost comparison with real numbers, see Hatchbox vs Heroku. For other platforms you could move to instead, see the best Heroku alternatives for Rails.
Leaving Heroku: questions
Still stuck? Ask us directly — a real person who has moved a lot of Rails apps off Heroku will answer.
Do I need to change my Rails code to leave Heroku?
rails_12factor on very old apps, can be removed.
How long does a Heroku to VPS migration take?
How do I move my Heroku Postgres database?
heroku pg:backups:capture and heroku pg:backups:download to get a latest.dump file, copy it to the new server, and restore it as the postgres user with pg_restore --no-owner --no-acl --role=your_app_user, skipping pg_stat_statements. Put the app in maintenance mode first so nothing is written during the copy.
What replaces Heroku Scheduler?
Can I keep using my Heroku add-ons?
Will Hatchbox help with the migration?
Simple, predictable pricing.
We charge per server, not per app. Run one application or twenty on the same box — the bill doesn't change.
$15
- Unlimited applications
- Deploy anywhere
- Zero downtime deployments
- Custom domains & free SSL
- Databases, cron jobs & background workers
- Full SSH access to your servers
- Real, human support
- 7 day free trial
Ready to deploy your Rails app?
Hatchbox has run more than 2 million deploys across 24,000+ applications since 2016. Start a 7 day free trial and put yours on a server you own.