Overview
DefDrive uses environment variables for configuration. Create a.env file in the root directory based on .env.example.
Required Variables
These variables must be set for DefDrive to run:DATABASE_URL
Type: String (PostgreSQL connection URL)Required: Yes
Used in:
main.go:25
PostgreSQL database connection URL in the format:
JWT_SECRET
Type: StringRequired: Yes
Used in:
middleware/auth.go:40, controllers/user.go:83
Secret key used for signing and verifying JWT authentication tokens.
Server Configuration
PORT
Type: IntegerRequired: No
Default:
8080Used in:
main.go:73
Port number on which the DefDrive server will listen.
HOST_URL
Type: String (URL)Required: Yes (for link generation)
Used in:
controllers/access.go:106
Base URL of your DefDrive instance, used for generating shareable file access links.
This URL is prepended to generated access links. Ensure it matches your actual deployment URL, including protocol (http/https) and port if non-standard.
Storage Configuration
DATA_PATH
Type: String (Directory path)Required: No
Default:
./data
Directory path where uploaded files will be stored.
STORAGE_TYPE
Type: String (local or minio)Required: No
Default:
local
Storage backend type for file uploads.
local- Store files on local filesystemminio- Store files in MinIO/S3-compatible storage (requires additional MinIO configuration)
MinIO support is currently commented out in the codebase. Use
local storage for current deployments.Database Configuration
These variables are used to construct theDATABASE_URL in Docker Compose setups:
DB_HOST
Type: StringDefault:
localhost
PostgreSQL database host.
POSTGRES_USER
Type: StringRequired: Yes (for Docker Compose) PostgreSQL database username.
POSTGRES_PASSWORD
Type: StringRequired: Yes (for Docker Compose) PostgreSQL database password.
POSTGRES_DB
Type: StringRequired: Yes (for Docker Compose)
Default:
defdrive
PostgreSQL database name.
DB_PORT
Type: IntegerDefault:
5432
PostgreSQL database port.
DB_DATA
Type: String (Directory path)Default:
./data/postgres
Directory path for PostgreSQL data files (used in local Docker volumes).
System Configuration
TZ
Type: String (Timezone)Default:
Asia/Kolkata
Timezone for the application container.
UID
Type: IntegerDefault:
1000
User ID for file permissions.
GID
Type: IntegerDefault:
1000
Group ID for file permissions.
MinIO Configuration (Optional)
MinIO support is currently commented out in the Docker Compose configuration. These variables are for future use.
MINIO_ROOT_USER
Type: String MinIO root username.MINIO_ROOT_PASSWD
Type: String MinIO root password.MINIO_PORT
Type: IntegerDefault:
9000
MinIO API port.
MINIO_CONSOLE_PORT
Type: IntegerDefault:
9001
MinIO console port.
MINIO_HOST
Type: StringDefault:
localhost
MinIO server host.
MINIO_BUCKET
Type: StringDefault:
msm
MinIO bucket name for file storage.
MINIO_DATA
Type: String (Directory path)Default:
./data/minio
Directory path for MinIO data.
Complete Example
Local Development
Production (Docker Compose)
Security Best Practices
-
Never commit
.envfiles to version control- Add
.envto.gitignore - Use
.env.exampleas a template
- Add
-
Use strong secrets for production
- Generate
JWT_SECRETwith cryptographically secure random data - Use complex database passwords
- Generate
-
Restrict database access
- Don’t expose PostgreSQL port publicly
- Use strong authentication
-
Use HTTPS in production
- Set
HOST_URLto usehttps:// - Configure SSL/TLS with a reverse proxy
- Set
-
Secure file storage
- Set appropriate permissions on
DATA_PATH - Regularly backup uploaded files
- Set appropriate permissions on
Troubleshooting
Environment Variables Not Loading
If environment variables aren’t being recognized:- Verify
.envfile exists in the root directory - Check for syntax errors in
.env(no spaces around=) - Restart the application after changes
Database Connection Errors
If you see “DATABASE_URL environment variable not set”:- Ensure
DATABASE_URLis set in your.envfile - Verify the format:
postgres://user:pass@host:port/database - Check that PostgreSQL is running and accessible
JWT Token Issues
If authentication fails:- Verify
JWT_SECRETis set and consistent - Don’t change
JWT_SECRETin production (invalidates all tokens) - Ensure the secret is the same across all instances
Next Steps
- Review Local Installation guide
- Set up Docker deployment
- Configure production security settings