Environment Variables

Environment variables are now reserved for container wiring, process bootstrap, and backward compatibility. For a current self-hosted installation, put application settings in config/config.json or edit supported settings in the Admin Panel.

The official ​Docker Compose [Recommended] deployment does not require a user-created .env file.

Configuration sources

Use ​Configuration as the primary guide.

  • config/config.json is the recommended source for server, mail, storage, indexer, and other application settings.

  • Settings saved in the Admin Panel are stored in the database.

  • Environment aliases are read during process startup. They are retained for compatibility, but should not be the primary application configuration source.

Database connection

DATABASE_URL is the supported database bootstrap variable:

DATABASE_URL=postgresql://user:password@postgres:5432/affine

The official Compose file sets it internally, so normal users do not need to configure it.

For a custom deployment:

  • Provide the complete DATABASE_URL to the application and migration processes.

  • URL-encode special characters in the username or password.

  • Do not also configure db.datasourceUrl with a different value. Native and Node processes can otherwise connect to different databases.

  • Do not change the database connection from the Admin Panel. It is a startup dependency and requires a controlled restart/migration procedure.

The following are obsolete Compose-template variables, not AFFiNE server configuration:

Obsolete variableCurrent replacement
DB_USERNAMEPut the username in DATABASE_URL for a custom deployment
DB_PASSWORDPut a URL-encoded password in DATABASE_URL for a custom deployment
DB_DATABASEPut the database name in DATABASE_URL for a custom deployment

Redis connection

The following variables remain supported for custom infrastructure deployments. The official Compose file supplies the required Redis host internally.

VariableDefaultDescription
REDIS_SERVER_HOSTlocalhostRedis host
REDIS_SERVER_PORT6379Redis port
REDIS_SERVER_USERNAMEemptyRedis username
REDIS_SERVER_PASSWORDemptyRedis password
REDIS_SERVER_DATABASE0First Redis database index; AFFiNE uses this index and the next four

For a long-lived deployment, prefer the equivalent redis section in config.json unless the orchestration platform owns these connection values.

Process networking

These variables control where the server process listens. They do not replace the public URL configuration.

VariableDefaultDescription
LISTEN_ADDR0.0.0.0Address the server process listens on
AFFINE_SERVER_PORT3010Port inside the application container

Set the public URL with server.externalUrl in config.json. Do not use AFFINE_SERVER_PORT to change only the host-side Docker port; edit the Compose port mapping instead.

Compatibility aliases

These aliases are still parsed by the Node configuration layer, but new self-hosted deployments should use the listed config.json keys.

Server and mail

Environment aliasconfig.json key
AFFINE_SERVER_EXTERNAL_URLserver.externalUrl
AFFINE_SERVER_HTTPSserver.https
AFFINE_SERVER_HOSTserver.host
AFFINE_SERVER_SUB_PATHserver.path
MAILER_SERVERNAMEmailer.SMTP.name
MAILER_HOSTmailer.SMTP.host
MAILER_PORTmailer.SMTP.port
MAILER_USERmailer.SMTP.username
MAILER_PASSWORDmailer.SMTP.password
MAILER_SENDERmailer.SMTP.sender
MAILER_IGNORE_TLSmailer.SMTP.ignoreTLS

Indexer and managed services

Environment aliasconfig.json key
AFFINE_INDEXER_ENABLEDindexer.enabled
AFFINE_INDEXER_SEARCH_PROVIDERindexer.provider.type
AFFINE_INDEXER_SEARCH_ENDPOINTindexer.provider.endpoint
AFFINE_INDEXER_SEARCH_API_KEYindexer.provider.apiKey
AFFINE_INDEXER_SEARCH_USERNAMEindexer.provider.username
AFFINE_INDEXER_SEARCH_PASSWORDindexer.provider.password
DOC_SERVICE_ENDPOINTdocService.endpoint
GA4_MEASUREMENT_IDtelemetry.ga4.measurementId
GA4_API_SECRETtelemetry.ga4.apiSecret

Changes made through environment aliases require a container restart.

Removed legacy Compose variables

The current official Compose file no longer reads these variables:

Removed variableCurrent behavior
AFFINE_REVISIONThe release Compose file specifies the image tag directly
PORTEdit the Compose host port mapping if needed
DB_DATA_LOCATIONPostgreSQL data is stored at ./data/postgres
UPLOAD_LOCATIONUploaded files are stored at ./data/storage
CONFIG_LOCATIONConfiguration is stored at ./config
DB_USERNAME, DB_PASSWORD, DB_DATABASEThe Compose network uses its internal database connection; custom deployments use DATABASE_URL

Do not copy these variables into a new .env file. Existing installations that still use an older Compose file should keep their matching legacy .env until they complete a backed-up migration.

Private key

Do not normally set AFFINE_PRIVATE_KEY. The self-host pre-deploy step creates and persists config/private.key automatically. Keep that file backed up and private; replacing it can invalidate encrypted or signed data.

Environment variables not documented on this page may be internal build, test, or managed-deployment controls and are not a stable self-host configuration interface.