Deploying Flask on Railway in 10 Minutes

Railway is a modern cloud platform that makes deploying Python apps trivial. No server management, no YAML configs, just push to GitHub and you're live.

Prerequisites

  • A Flask app in a GitHub repo
  • A free Railway account (railway.app)

Step 1: Add a Procfile

Create Procfile in your project root:

web: gunicorn app:app

Install gunicorn:

pip install gunicorn
pip freeze > requirements.txt

Step 2: Add runtime.txt (optional)

python-3.11.9

Step 3: Environment Variables

Don't hardcode secrets. Railway has a built-in env var editor:

  1. Open your project → Settings → Variables
  2. Add SECRET_KEY, DATABASE_URL, etc.

In your Flask app:

import os
app.secret_key = os.environ['SECRET_KEY']

Step 4: Deploy

  1. Go to railway.app → New Project → Deploy from GitHub repo
  2. Select your repo
  3. Railway detects Python automatically
  4. Hit Deploy → Done.

Railway gives you a URL like https://myapp.up.railway.app immediately.

Continuous Deployment

Every push to main triggers a redeploy. To disable this, go to Settings → Deployments → Manual triggers.

Adding a Custom Domain

Settings → Domains → Add custom domain → Update your DNS CNAME.

Viewing Logs

railway logs

Or open the Railway dashboard → Deployments → Logs.

Pro Tips

  • Use railway run python seed.py to run one-off scripts
  • Link a Railway PostgreSQL plugin for a free managed database
  • Set PORT env var is handled automatically by Railway

That's it. Your Flask app is now live.