Setting Up the DIFY Development Environment
作者:qiqiqi 阅读次数:

Docker Compose Method

Quick Start

The easiest way to launch the Dify server is by running our docker-compose.yml file. Ensure Docker and Docker Compose 

are installed on your machine before executing the command:

cd docker

docker-compose up -d   (Tested and confirmed to start successful)

Once the command completes, access http://localhost/install in your browser. This will take you to the Dify console where you can begin the initial setup.

Local Development

Backend Environment

D:\aiWorkspace> git clone https://github.com/langgenius/dify.git
D:\aiWorkspace>cd dify
D:\aiWorkspace\dify>cd api
D:\aiWorkspace\dify\api>python -m venv venv   #Set up Dify’s virtual runtime environment to prevent package version conflicts.
D:\aiWorkspace\dify\api>venv\Scripts\activate #Activate Dify’s virtual Python environment.
[root@unassigned api]# source /www/wwwroot/dify/api/venv/bin/activate #Launch the virtual Python environment on Linux.


(venv) D:\aiWorkspace\dify\api>pip install -r requirements.txt   #Install the required package versions within the virtual environment.

#############Post-installation, set up databases like Redis, PostgreSQL (PG-SQL), and Weaviate (a vector database) on your Linux system.
[root@vmcentos8 docker]# docker-compose -f docker-compose.middleware.yaml up -d #Launch middleware containers using Docker.
WARN[0000] Found orphan containers ([docker-nginx-1 docker-worker-1 docker-api-1 docker-web-1]) for this prot up. 
[+] Running 3/3
 ⠿ Container docker-redis-1     Started                                                                     
 ⠿ Container docker-weaviate-1  Started                                                                     
 ⠿ Container docker-db-1        Started

# Here are the ports that need to be opened:
[root@vmcentos8 docker]# firewall-cmd --add-port=8080/tcp --permanent
success
[root@vmcentos8 docker]# firewall-cmd --add-port=6379/tcp --permanent
success
[root@vmcentos8 docker]# firewall-cmd --add-port=5432/tcp --permanent
success
[root@vmcentos8 docker]# firewall-cmd --reload
success
[root@vmcentos8 docker]# firewall-cmd --list-ports
22/tcp 80/tcp 5432/tcp 6379/tcp 8080/tcp 39002/tcp

[root@vmcentos8 docker]# openssl rand -base64 42 #Generate a key.


######Below shows how to configure the system environment in VSCode.
Copy .env.example to .env ###Consult the .env file for key configuration, middleware IP addresses, and ports.

###Initialize the database using the flask db command.
(venv) [root@unassigned api]# flask db upgrade
INFO  [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO  [alembic.runtime.migration] Will assume transactional DDL.
INFO  [alembic.runtime.migration] Running upgrade  -> 64b051264f32, init
INFO  [alembic.runtime.migration] Running upgrade 64b051264f32 -> 9f4e3427ea84, add created by role
INFO  [alembic.runtime.migration] Running upgrade 9f4e3427ea84 -> a45f4dfde53b, add language to recommend apps
'

#######Start the backend API in debug mode.   #######################
(venv) D:\aiWorkspace\dify\api>flask run --host 0.0.0.0 --port=5001 --debug
 * Debug mode: on
INFO:werkzeug:WARNING: This is a development server. Do not use it in a production deployment. Use a production
 WSGI server instead.
 * Running on all addresses (0.0.0.0)
 * Running on http://127.0.0.1:5001
 * Running on http://192.168.1.3:5001
INFO:werkzeug:Press CTRL+C to quit
INFO:werkzeug: * Restarting with stat
WARNING:werkzeug: * Debugger is active!
INFO:werkzeug: * Debugger PIN: 114-212-881

###Configure and launch the Dify API as follows.
Setup your application by visiting http://localhost:5001/console/api/setup or other apis...
If you need to debug local async processing, you can run celery -A app.celery worker, celery can do dataset importing and other async tasks.

###Backend environment setup is now complete.##############################################
# Server Edition
EDITION=SELF_HOSTED

# Your App secret key will be used for securely signing the session cookie
# Make sure you are changing this key for your deployment with a strong key.
# You can generate a strong key using `openssl rand -base64 42`.
# Alternatively you can set it with `SECRET_KEY` environment variable.
SECRET_KEY=KIcpt1YGncmH/HQw7KyasUhFMY2z4mzFnnxkd3xnzE62LdnlNXXsvn01

# Console API base URL
CONSOLE_URL=http://localhost:5001  #Ensure both the port and 3000 are configured to use ‘localhost’ and the same domain name; otherwise, login will be disabled.

# Service API base URL
API_URL=http://localhost:5001

# Web APP base URL
APP_URL=http://localhost:5001

# celery configuration
CELERY_BROKER_URL=redis://:difyai123456@192.168.1.4:6379/1

# redis configuration
REDIS_HOST=192.168.1.4
REDIS_PORT=6379
REDIS_PASSWORD=difyai123456
REDIS_DB=0

# PostgreSQL database configuration
DB_USERNAME=postgres
DB_PASSWORD=difyai123456
DB_HOST=192.168.1.4
DB_PORT=5432
DB_DATABASE=dify

# Storage configuration
# use for store upload files, private keys...
# storage type: local, s3
STORAGE_TYPE=local
STORAGE_LOCAL_PATH=storage
S3_ENDPOINT=https://your-bucket-name.storage.s3.clooudflare.com
S3_BUCKET_NAME=your-bucket-name
S3_ACCESS_KEY=your-access-key
S3_SECRET_KEY=your-secret-key
S3_REGION=your-region

# CORS configuration
WEB_API_CORS_ALLOW_ORIGINS=http://localhost:3000,*
CONSOLE_CORS_ALLOW_ORIGINS=http://localhost:3000,*

# Cookie configuration
COOKIE_HTTPONLY=true
COOKIE_SAMESITE=Lax
COOKIE_SECURE=false

# Session configuration
SESSION_PERMANENT=true
SESSION_USE_SIGNER=true

## support redis, sqlalchemy
SESSION_TYPE=redis

# session redis configuration
SESSION_REDIS_HOST=192.168.1.4
SESSION_REDIS_PORT=6379
SESSION_REDIS_PASSWORD=difyai123456
SESSION_REDIS_DB=2

# Vector database configuration, support: weaviate, qdrant
VECTOR_STORE=weaviate

# Weaviate configuration
WEAVIATE_ENDPOINT=http://192.168.1.4:8080
WEAVIATE_API_KEY=WVF5YThaHlkYwhGUSmCRgsX3tD5ngdN8pkih
WEAVIATE_GRPC_ENABLED=false

# Qdrant configuration, use `path:` prefix for local mode or `https://your-qdrant-cluster-url.qdrant.io` for remote mode
QDRANT_URL=path:storage/qdrant
QDRANT_API_KEY=your-qdrant-api-key

# Sentry configuration
SENTRY_DSN=

# DEBUG
DEBUG=false
SQLALCHEMY_ECHO=false

Frontend Environment

D:\aiWorkspace\dify\web>nvm list  #Check the current Node.js version.

  * 16.14.2 (Currently using 64-bit executable)
    12.22.12

D:\aiWorkspace\dify\web>pnpm dev #It was found that pnpm is not installed.
'pnpm' is not recognized as an internal or external command,
operable program or batch file.

D:\aiWorkspace\dify\web>npm install pnpm -g  #Install pnpm for the current Node.js environment.
D:\aiWorkspace\dify\web>pnpm install  #Install the required packages for the Dify project.

D:\aiWorkspace\dify\web>pnpm dev	' ###Start the Dify project.'

> dify-web@0.2.0 dev D:\aiWorkspace\dify\web
> next dev

ready - started server on 0.0.0.0:3000, url: http://localhost:3000
warn  - You have enabled experimental feature (appDir) in next.config.js.
info  - Thank you for testing `appDir` please leave your feedback at https://nextjs.link/app-feedback
warn  - Experimental features are not covered by semver, and may cause unexpected or broken application behavior. Use at
 your own risk.

info  - VS Code settings.json has been created for Next.js' automatic app types, this file can be added to .gitignore if
 desired
Attention: Next.js now collects completely anonymous telemetry regarding usage.
This information is used to shape Next.js' roadmap and prioritize features.
You can learn more, including how to opt-out if you'd not like to participate in this anonymous program, by visiting the
 following URL:
https://nextjs.org/telemetry

info  - automatically enabled Fast Refresh for 1 custom loader
event - compiled client and server successfully in 1627 ms (262 modules)
wait  - compiling...
event - compiled client and server successfully in 214 ms (262 modules)
# For production release, change this to PRODUCTION
NEXT_PUBLIC_DEPLOY_ENV=PRODUCTION
# The deployment edition, SELF_HOSTED or CLOUD
NEXT_PUBLIC_EDITION=SELF_HOSTED
# The base URL of console application, refers to the Console base URL of WEB service if console domain is
# different from api or web app domain.
# example: http://cloud.dify.ai/console/api
NEXT_PUBLIC_API_PREFIX=http://localhost:5001/console/api  #Make sure the backend runs on ‘localhost’ and matches the frontend’s ‘localhost’ configuration; otherwise, various unexpected errors may occur.
# The URL for Web APP, refers to the Web App base URL of WEB service if web app domain is different from
# console or api domain.
# example: http://udify.app/api
NEXT_PUBLIC_PUBLIC_API_PREFIX=http://localhost:5001/api

# SENTRY
NEXT_PUBLIC_SENTRY_DSN=
NEXT_PUBLIC_SENTRY_ORG=
NEXT_PUBLIC_SENTRY_PROJECT=


返回列表

扫码关注不迷路!!!

郑州升龙商业广场B座25层

service@iqiqiqi.cn

企起期科技 qiqiqi

联系电话:187-0363-0315

联系电话:199-3777-5101