By 蓉爸 RungBa
Created: 2025-01-26
Revised: 2025-01-26
繼使用 LXD/LXC 完成 n8n 的自架後,接下來就再來試試 Dify 的自架!
一樣,我不想用 Docker 方式來架設,但花了一些時間,Google 到的都是使用 Docker 的安裝方式,突然想到我該來問問 Claude 的,於是就有了下方的成果,待我試試 Claude 3.5 給的 installation guide …
不想用 Docker 方式架設的原因:
因 Docker 安裝後,整個 container image 會非常肥大,比一般不用Docker 方式建置的 image 大了 10 ~ 20 倍,而且也不利於備份,甚至發現備份時,無法成功匯出 container image,目前不確定是否是 LXD 系統本身還存在這個問題?!
First, install required system packages:
sudo apt update
sudo apt install -y python3-pip python3-venv postgresql postgresql-contrib redis-server nodejs npm git
sudo systemctl start postgresql
sudo systemctl enable postgresql
sudo -u postgres psql
CREATE DATABASE dify;
CREATE USER dify WITH PASSWORD 'your_password';
GRANT ALL PRIVILEGES ON DATABASE dify TO dify;
\q
sudo systemctl start redis-server
sudo systemctl enable redis-server
git clone https://github.com/langgenius/dify.git
cd dify
python3 -m venv venv
source venv/bin/activate
cd api
pip install -r requirements.txt
cp .env.example .env
Edit .env file with your database and Redis configurations:
# Database
DB_USERNAME=dify
DB_PASSWORD=your_password
DB_HOST=localhost
DB_PORT=5432
DB_DATABASE=dify
# Redis
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_USERNAME=
REDIS_PASSWORD=
REDIS_DB=0
cd ../web
npm install
npm run build
From the api directory:
flask db upgrade
flask init
cd api
flask run --host 0.0.0.0 --port 5001
cd web
npm run dev
Access the web interface at: http://localhost:3000
If you encounter PostgreSQL authentication issues:
If Redis connection fails:
sudo systemctl status redis-server
Python package conflicts:
Port conflicts:
For production deployment, additional steps are recommended: