MEMOS_ and use underscores instead of hyphens.
How Environment Variables Work
Memos uses Viper for configuration management with automatic environment variable binding:- All flags are automatically bound to environment variables
- Prefix:
MEMOS_ - Replace hyphens with underscores (e.g.,
--databecomesMEMOS_DATA) - Environment variables take precedence over default values but not over explicit flags
cmd/memos/main.go:134-136
Core Server Variables
HTTP port for the server to listen on.The server will be accessible at
http://localhost:5230Bind address for the server. Empty means all interfaces (0.0.0.0).Use
127.0.0.1 for local development to prevent external access.Path to Unix socket file. When set, this overrides Useful for reverse proxy setups with nginx or Apache.
MEMOS_ADDR and MEMOS_PORT.Data Storage Variables
Data directory for SQLite database and local file storage.Default behavior:Source:
- Windows:
%ProgramData%\memos - Linux/macOS (Docker):
/var/opt/memosif writable - Linux/macOS (Local):
.(current directory)
internal/profile/profile.go:58-80Database driver to use.Supported values:Source:
sqlite- SQLite (recommended for single server)mysql- MySQL/MariaDBpostgres- PostgreSQL
store/db/db.go:18-27Database connection string (DSN - Data Source Name).Default behavior:
- If
MEMOS_DRIVER=sqliteand DSN is empty, defaults to{MEMOS_DATA}/memos_prod.db - For MySQL/PostgreSQL, DSN is required
Instance Configuration
The public URL of your Memos instance. Used for:
- OAuth2 redirect URIs
- Email links
- RSS feed URLs
- API webhook callbacks
Enable demo mode for testing and development.Demo mode features:Source:
- Uses
memos_demo.dbinstead ofmemos_prod.db - Seeds database with sample data on first run
- Shows database DSN in startup logs
- Not for production use
cmd/memos/main.go:29, internal/profile/profile.go:98-103Command-Line Flags
All environment variables have corresponding command-line flags:| Flag | Env Variable | Default | Description |
|---|---|---|---|
--demo | MEMOS_DEMO | false | Enable demo mode |
--addr | MEMOS_ADDR | "" | Bind address |
--port | MEMOS_PORT | 8081 | HTTP port |
--unix-sock | MEMOS_UNIX_SOCK | "" | Unix socket path |
--data | MEMOS_DATA | auto | Data directory |
--driver | MEMOS_DRIVER | sqlite | Database driver |
--dsn | MEMOS_DSN | auto | Database connection string |
--instance-url | MEMOS_INSTANCE_URL | "" | Instance URL |
cmd/memos/main.go:100-107
Examples
Development Setup
Production with PostgreSQL
Docker Environment Variables
Using Unix Socket with Nginx
Priority Order
When the same configuration is specified in multiple ways:- Command-line flags (highest priority)
- Environment variables
- Default values (lowest priority)
Validation
Memos validates configuration on startup:- Data directory must exist and be writable
- DSN is required for MySQL/PostgreSQL drivers
- Port must be between 1-65535
- Unix socket path must be valid
internal/profile/profile.go:57-107