- Python 3.10+ with pip and virtual environment support
- Docker & Docker Compose for containerized development
- Git for cloning repositories
- Node.js 16+ for frontend development (optional)
- VS Code with Python extension
- Postman or similar for API testing
- pgAdmin or database client for debugging
Pros: Consistent environment, easy setup, includes all services Cons: Slightly slower for rapid iteration
# Clone the Dify repository
git clone https://github.com/langgenius/dify.git
cd dify
# Start all services with Docker Compose
docker-compose up -d
# Verify services are running
docker-compose ps
# Access the application
# - Web UI: http://localhost:3000
# - API: http://localhost:5001
# - Admin: http://localhost:3000/adminPros: Faster development iteration, easier debugging Cons: More complex setup, requires manual service management
# Clone and setup API backend
git clone https://github.com/langgenius/dify.git
cd dify/api
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Setup database (PostgreSQL required)
# Edit .env file with your database credentials
cp .env.example .env
# Run database migrations
flask db upgrade
# Start the API server
python app.pyKey environment variables in docker-compose.yml:
environment:
# Database
DB_USERNAME: postgres
DB_PASSWORD: difyai123456
DB_HOST: db
DB_PORT: 5432
DB_DATABASE: dify
# Redis
REDIS_HOST: redis
REDIS_PORT: 6379
# OpenAI API (add your key)
OPENAI_API_KEY: sk-your-key-here
# Security
SECRET_KEY: your-secret-key
# Application
APP_ENV: development
DEBUG: trueFor local development, create .env file:
# Application
APP_ENV=development
DEBUG=true
SECRET_KEY=your-secret-key-here
# Database
DB_USERNAME=postgres
DB_PASSWORD=your-password
DB_HOST=localhost
DB_PORT=5432
DB_DATABASE=dify
# Redis
REDIS_HOST=localhost
REDIS_PORT=6379
# LLM Providers
OPENAI_API_KEY=sk-your-openai-key
ANTHROPIC_API_KEY=your-anthropic-key
# Vector Database (optional)
WEAVIATE_ENDPOINT=http://localhost:8080
WEAVIATE_API_KEY=your-keyWhen you run Dify, these services start:
graph TB
A[Web UI :3000] --> B[API Server :5001]
B --> C[PostgreSQL :5432]
B --> D[Redis :6379]
B --> E[Vector DB :8080]
B --> F[Worker Queue]
subgraph "External Services"
G[OpenAI API]
H[Other LLM APIs]
end
B --> G
B --> H
# Check all containers are running
docker-compose ps
# Should show:
# - dify-web (port 3000)
# - dify-api (port 5001)
# - dify-worker
# - postgres (port 5432)
# - redis (port 6379)
# - weaviate (port 8080)# Health check
curl http://localhost:5001/health
# Should return: {"status": "healthy"}
# API version
curl http://localhost:5001/v1/
# Should return API version info- Open http://localhost:3000
- Create admin account
- Login and explore the interface
- Try creating a simple chatbot application
Frontend Changes:
# For UI modifications
cd web
npm install
npm run dev
# Changes auto-reload at http://localhost:3001Backend Changes:
# For API modifications
cd api
# If using Docker, rebuild:
docker-compose build api
docker-compose up -d
# If running locally:
source venv/bin/activate
python app.pyVS Code Launch Configuration:
.vscode/launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Dify API",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/api/app.py",
"console": "integratedTerminal",
"cwd": "${workspaceFolder}/api",
"env": {
"FLASK_ENV": "development"
}
}
]
}# If ports are already in use, modify docker-compose.yml:
ports:
- "3001:3000" # Web UI
- "5002:5001" # API# Reset database:
docker-compose down
docker volume rm dify_postgres_data
docker-compose up -d# Fix Docker permissions:
sudo chown -R $USER:$USER .Once your environment is running:
- Explore the Web Interface - Create your first application
- Review the API Documentation - Test endpoints with Postman
- Check the Database Schema - Understand the data model
- Read the Architecture Guide - Core Architecture
- Setup Issues: Open an issue with
[setup]tag - Dify Community: Official Dify Discord
- Docker Problems: Check Docker documentation
✅ Environment ready? Continue to System Overview