---
title: "Deploy a Rails App"
description: "Deploy a Ruby on Rails application on Miget with git push, PostgreSQL, and automatic buildpack detection."
---
Miget detects Ruby on Rails from your `Gemfile` and runs your app with no configuration. You push your code, Miget builds it, and your Rails server goes live.
## Prerequisites
Before you start, make sure you have:
- A [Miget account](https://app.miget.com)
- Git installed locally
- A Rails app with a `Gemfile` committed to a Git repository
## Bind to the right port
Every app on Miget must listen on `0.0.0.0:5000`. Miget sets an immutable `PORT=5000`, and public traffic only reaches port `5000`.
Puma respects the `PORT` environment variable, so `rails server` binds to `5000` automatically. No changes needed for the default setup.
If you want to control the start command explicitly, add a `Procfile` to your project root:
```procfile Procfile
web: bundle exec rails server -b 0.0.0.0 -p 5000
```
Learn more about [ports](/networking/ports) and [buildpacks](/overview/buildpacks).
## Set environment variables
Add these variables to your app before deploying. Set them under your app's settings - see [using secrets](/deployments/using-secrets).
| Variable | Value | Purpose |
| --- | --- | --- |
| `RAILS_ENV` | `production` | Run in production mode |
| `SECRET_KEY_BASE` | your secret | Required by Rails to sign sessions and cookies |
| `RAILS_SERVE_STATIC_FILES` | `true` | Serve precompiled assets from the app |
Generate a `SECRET_KEY_BASE` locally with `bundle exec rails secret` and paste the value into Miget.
## Deploy your app
Go to [app.miget.com](https://app.miget.com), click **New** then **Application**. Give your app a name, pick a resource, and click **Next**.
Select **Auto detection (Miget Buildpacks)** and choose a size, then click **Next**. Miget will detect Ruby from your `Gemfile`, detect Rails, and run the Rails server.
Choose **git push** as the deployment method, click **Create**, and copy the token shown.
Add the Miget remote and push:
```bash
git remote add miget https://git..miget.io//
git push miget
```
Miget builds your app and starts the Rails server. See [git push to builder](/deployments/git-push-to-builder) for the full reference.
This guide uses **git push**, but it's one of several ways to deploy. You can also connect a [GitHub repository](/deployments/github-integration) for auto-deploys and pull request previews, deploy from a public Git repository, or push a prebuilt [container image](/deployments/container-registry). See [all deployment methods](/deployments/how-it-works).
### Precompile assets and run migrations
Precompile your assets during the build or as a post-deploy step:
```bash
bundle exec rails assets:precompile
```
Run database migrations as a post-deploy step so they execute after each new release:
```bash
bundle exec rails db:migrate
```
## Connect a database
Rails reads `DATABASE_URL` automatically, so connecting a database takes no code changes.
Add a [PostgreSQL](/databases/postgresql) addon to your app. Miget provisions the database and auto-injects a `DATABASE_URL` (`postgres://...`) into your app's environment.
Rails picks up `DATABASE_URL` on boot. Run `bundle exec rails db:migrate` as a post-deploy step to set up your schema.
You do not need to edit `database.yml` beyond honoring `DATABASE_URL`, which recent Rails versions do out of the box.
## Next steps
Point your own domain at your Rails app.
Store `SECRET_KEY_BASE` and other config securely.
Learn how Miget provisions and injects your database.
Understand how Miget allocates compute across your apps.