Self-Host Dify
Dify is an open-source platform for building LLM-powered applications. It provides a visual workflow editor, built-in RAG pipeline, agent framework, and API management through a web interface.
Dify is a multi-service application that requires an API server, a worker, a web frontend, Postgres, and Redis. Railway is well-suited for this type of deployment since each component runs as a separate service with shared private networking.
Dify calls external LLM APIs (OpenAI, Anthropic, etc.) for model inference. Railway is CPU-based and does not offer GPU instances.
What you will set up
- Dify API server, worker, and web frontend as separate Railway services
- PostgreSQL and Redis databases
- Persistent storage for uploaded files
- A public domain for the Dify web interface
One-click deploy from a template
Railway has a Dify template that provisions all services and databases in one step.
After deploying, skip to Configure LLM providers to connect your API keys.
If you prefer to set things up manually, continue below.
Manual deployment
1. Create the project and databases
- Create a new project on Railway.
- Add PostgreSQL: click + New > Database > PostgreSQL.
- Add Redis: click + New > Database > Redis.
2. Deploy the API server
- Click + New > Docker Image.
- Enter
langgenius/dify-apias the image name. - Add the following environment variables, using reference variables for database connections:
| Variable | Value |
|---|---|
MODE | api |
DB_HOST | ${{Postgres.PGHOST}} |
DB_PORT | ${{Postgres.PGPORT}} |
DB_USERNAME | ${{Postgres.PGUSER}} |
DB_PASSWORD | ${{Postgres.PGPASSWORD}} |
DB_DATABASE | ${{Postgres.PGDATABASE}} |
REDIS_HOST | ${{Redis.REDISHOST}} |
REDIS_PORT | ${{Redis.REDISPORT}} |
REDIS_PASSWORD | ${{Redis.REDISPASSWORD}} |
SECRET_KEY | A random string (use openssl rand -hex 32) |
STORAGE_TYPE | local |
STORAGE_LOCAL_PATH | /app/api/storage |
- Attach a Volume mounted at
/app/api/storagefor file uploads. - Generate a public domain for the API server.
3. Deploy the worker
- Click + New > Docker Image.
- Enter
langgenius/dify-apias the image name (same image, different mode). - Copy the same environment variables from the API server, but change:
| Variable | Value |
|---|---|
MODE | worker |
- No public domain is needed. The worker communicates with Postgres and Redis over private networking.
4. Deploy the web frontend
- Click + New > Docker Image.
- Enter
langgenius/dify-webas the image name. - Add the following environment variable:
| Variable | Value |
|---|---|
CONSOLE_API_URL | The public URL of your API server (e.g., https://dify-api-production-xxxx.up.railway.app) |
APP_API_URL | Same as CONSOLE_API_URL |
- Generate a public domain for the web frontend.
Configure LLM providers
- Open the web frontend domain in your browser.
- Create an admin account on first access.
- Go to Settings > Model Providers.
- Add your LLM API keys (OpenAI, Anthropic, or others).
Dify stores provider credentials encrypted in Postgres.
Next steps
- Manage Volumes: Resize or back up your persistent storage.
- Set up a custom domain: Use your own domain for the Dify interface.
- Private Networking: How services communicate within a project.
- Monitor your app: View logs and metrics for your Dify services.