[PR #292] [MERGED] correct instruction to generate and replace SECRET_KEY value in .env file #412

Closed
opened 2026-02-16 11:20:43 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/langgenius/dify-docs-archived/pull/292
Author: @bowenliang123
Created: 9/26/2024
Status: Merged
Merged: 9/26/2024
Merged by: @crazywoola

Base: mainHead: secret-key


📝 Commits (1)

📊 Changes

5 files changed (+5 additions, -8 deletions)

View changed files

📝 en/getting-started/install-self-hosted/environments.md (+1 -1)
📝 en/getting-started/install-self-hosted/local-source-code.md (+1 -2)
📝 jp/getting-started/install-self-hosted/local-source-code.md (+1 -2)
📝 zh_CN/getting-started/install-self-hosted/environments.md (+1 -1)
📝 zh_CN/getting-started/install-self-hosted/local-source-code.md (+1 -2)

📄 Description

Before this PR:
Failed to replace value in .env file with sed on Mac.

Pasted Graphic

(dify-api-py3.10) bw@bwdeMacBook-Pro-2 api % sed -i 's/SECRET_KEY=.*/SECRET_KEY=QDyaHv8M5kuJ6XpNxEHXZ0OD6B029cKNrOt+VPxky70ixTGAwRBNtULn/' .env
sed: 1: ".env": invalid command code .

With this PR:

To solve this problem,

Possible approach 1 with sed :

On Mac:
sed -i '' "s/^SECRET_KEY=.*/SECRET_KEY=$(printf '%s' "$(openssl rand -base64 42)" | sed 's/[\/&]/\\&/g')/" .env

On Linux:
sed -i "s/^SECRET_KEY=.*/SECRET_KEY=$(printf '%s' "$(openssl rand -base64 42)" | sed 's/[\/&]/\\&/g')/" .env

Possible approach 2 with awk (recommended and used in this PR as it has clear syntax without escaping characters like sed):

 awk -v key="$(openssl rand -base64 42)" '/^SECRET_KEY=/ {sub(/=.*/, "=" key)} 1' .env > temp_env && mv temp_env .env

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/langgenius/dify-docs-archived/pull/292 **Author:** [@bowenliang123](https://github.com/bowenliang123) **Created:** 9/26/2024 **Status:** ✅ Merged **Merged:** 9/26/2024 **Merged by:** [@crazywoola](https://github.com/crazywoola) **Base:** `main` ← **Head:** `secret-key` --- ### 📝 Commits (1) - [`c414261`](https://github.com/langgenius/dify-docs-archived/commit/c414261624f516cf04ee3c506103d1b12fd269d0) update doc ### 📊 Changes **5 files changed** (+5 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `en/getting-started/install-self-hosted/environments.md` (+1 -1) 📝 `en/getting-started/install-self-hosted/local-source-code.md` (+1 -2) 📝 `jp/getting-started/install-self-hosted/local-source-code.md` (+1 -2) 📝 `zh_CN/getting-started/install-self-hosted/environments.md` (+1 -1) 📝 `zh_CN/getting-started/install-self-hosted/local-source-code.md` (+1 -2) </details> ### 📄 Description Before this PR: Failed to replace value in `.env` file with `sed` on Mac. <img width="1171" alt="Pasted Graphic" src="https://github.com/user-attachments/assets/c8a9eaf3-7264-4e64-92ec-1cf5cd07c6c8"> (dify-api-py3.10) bw@bwdeMacBook-Pro-2 api % sed -i 's/SECRET_KEY=.*/SECRET_KEY=QDyaHv8M5kuJ6XpNxEHXZ0OD6B029cKNrOt+VPxky70ixTGAwRBNtULn/' .env sed: 1: ".env": invalid command code . With this PR: To solve this problem, Possible approach 1 with `sed` : ``` On Mac: sed -i '' "s/^SECRET_KEY=.*/SECRET_KEY=$(printf '%s' "$(openssl rand -base64 42)" | sed 's/[\/&]/\\&/g')/" .env On Linux: sed -i "s/^SECRET_KEY=.*/SECRET_KEY=$(printf '%s' "$(openssl rand -base64 42)" | sed 's/[\/&]/\\&/g')/" .env ``` Possible approach 2 with `awk` (recommended and used in this PR as it has clear syntax without escaping characters like `sed`): ``` awk -v key="$(openssl rand -base64 42)" '/^SECRET_KEY=/ {sub(/=.*/, "=" key)} 1' .env > temp_env && mv temp_env .env ``` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-16 11:20:43 -05:00
yindo closed this issue 2026-02-16 11:20:43 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify-docs-archived#412