docs/docs/en/nocobase-cli/installation/env.md
.envThis page only applies to applications created or hosted via the NocoBase CLI.
If you have just finished reading Install using CLI and have seen the "Installation Directory" section, then the most common problems you will encounter are usually the following:
.env file placed?.envnb env updateLet’s talk about the conclusion first:
.env is placed in <app-path>/.env by defaultAPP_KEY, TZ, APP_PORT, APP_PUBLIC_PATH, and DB_* are managed by nb env update by default..env is mainly used to supplement runtime variables that the CLI has not directly taken over, such as storage, cache, logs, observations and some plug-in extension variables.app-path firstIn [Install using CLI](./cli.md#Installation directory), the default directory structure of CLI env is as follows:
<app-path>/
├── source/
├── storage/
└── .env
If you are not sure where the currently applied app-path is, you can check directly:
nb env info app1 --field app.appPath
Just replace app1 with your env name.
That is, for an application created or hosted via the CLI, the most appropriate location for the .env file is:
<app-path>/.env
Generally speaking, there is no need to put it in source/.env, and there is no need to find .env in the root directory of the Docker Compose project according to the old installation method.
.env yourself?.env is optional.
If you just want to run the application first, or just modify basic configurations such as ports, time zones, database connections, and public access paths, then in many cases there is no need to manually create .env.
Only add them to <app-path>/.env if you need to add some runtime variables that the CLI has not directly taken over.
nb env update firstIn the new CLI installation method, it is recommended that the basic application configuration be given priority to nb env update by default.
This has two benefits:
nb env updateFor the following items, you may have been used to writing them directly into .env in the past. However, in CLI installation mode, it is recommended to use nb env update by default:
| I want to change... | How to change the default |
|---|---|
APP_KEY | nb env update <name> --app-key <value> |
TZ | nb env update <name> --timezone <value> |
APP_PORT | nb env update <name> --app-port <value> |
APP_PUBLIC_PATH | nb env update <name> --app-public-path <value> |
CDN_BASE_URL | nb env update <name> --cdn-base-url <value> |
Database type and connection parameters, such as DB_DIALECT, DB_HOST, DB_PORT, DB_DATABASE, DB_USER, DB_PASSWORD | nb env update <name> --db-dialect ... --db-host ... --db-port ... --db-database ... --db-user ... --db-password ... |
PostgreSQL schema, table prefix, underscore naming such database supplementary items, such as DB_SCHEMA, DB_TABLE_PREFIX, DB_UNDERSCORED | nb env update <name> --db-schema ... --db-table-prefix ... --db-underscored |
For example, if you want to change the application port and time zone, you can write directly like this:
nb env update app1 --app-port 13080 --timezone Asia/Shanghai
If you want to change the database connection parameters, you can write like this:
nb env update app1 \
--db-dialect postgres \
--db-host 127.0.0.1 \
--db-port 5432 \
--db-database nocobase \
--db-user nocobase \
--db-password nocobase
After making the changes, the CLI will usually prompt you to execute nb app restart later. For a more complete parameter description, just see nb env update.
.envIf a variable does not yet have a corresponding CLI parameter, or it is more like an extended configuration "passed directly to the application runtime", then just continue to write <app-path>/.env.
Usually include these categories:
LOCAL_STORAGE_*, AWS_S3_*, ALI_OSS_*, TX_COS_*CACHE_*, REDIS_URLLOGGER_*, TELEMETRY_*for example:
LOCAL_STORAGE_DEST=storage/uploads
AWS_S3_BUCKET=your-bucket
AWS_S3_REGION=ap-southeast-1
LOGGER_LEVEL=info
REDIS_URL=redis://127.0.0.1:6379
This type of variable is essentially an application runtime configuration, and the CLI currently will not take over it item by item. It is most natural to place it in .env.
.env and nb env updateIf you're not sure where a certain configuration should go, just follow this rule by default:
nb env update already has a corresponding parameter, it will be used first by default.<app-path>/.envIn most scenarios, this division of labor is sufficient.
Do not maintain two copies of the same configuration at the same time.
For example, if you have saved basic items such as APP_PORT, TZ, APP_PUBLIC_PATH, and DB_HOST with nb env update, you usually don’t need to write them again in .env. Otherwise, when troubleshooting problems later, it will be easy to not tell which layer is the value you really want to take effect.
.env exampleIf your basic configuration has been saved through the CLI, then .env probably only needs to retain a few extension variables, such as:
LOGGER_LEVEL=info
REDIS_URL=redis://127.0.0.1:6379
AWS_S3_BUCKET=your-bucket
AWS_S3_REGION=ap-southeast-1
This is also the mentality that this page most wants to help you build:
.env is still useful, but in the new CLI installation method, it is more about supplementing the runtime extension configuration rather than continuing to assume all basic installation parameters.
nb env update