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:
- Open your project → Settings → Variables
- Add
SECRET_KEY,DATABASE_URL, etc.
In your Flask app:
import os
app.secret_key = os.environ['SECRET_KEY']
Step 4: Deploy
- Go to railway.app → New Project → Deploy from GitHub repo
- Select your repo
- Railway detects Python automatically
- 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.pyto run one-off scripts - Link a Railway PostgreSQL plugin for a free managed database
- Set
PORTenv var is handled automatically by Railway
That's it. Your Flask app is now live.
0 Comments
Join the conversation
No comments yet. Be the first!