[GH-ISSUE #533] Custom location of .env file? #339

Closed
opened 2026-03-03 01:28:08 +03:00 by kerem · 5 comments
Owner

Originally created by @MrMEEE on GitHub (Jul 15, 2019).
Original GitHub issue: https://github.com/dani-garcia/vaultwarden/issues/533

Hi..

Is there any way to specify a custom location of the .env file??

Originally created by @MrMEEE on GitHub (Jul 15, 2019). Original GitHub issue: https://github.com/dani-garcia/vaultwarden/issues/533 Hi.. Is there any way to specify a custom location of the .env file??
kerem closed this issue 2026-03-03 01:28:09 +03:00
Author
Owner

@dani-garcia commented on GitHub (Jul 15, 2019):

You can use the CONFIG_FILE environment variable, which should point to the exact JSON file.

The exact line of code: github.com/dani-garcia/bitwarden_rs@05a1137828/src/config.rs (L14)

<!-- gh-comment-id:511532468 --> @dani-garcia commented on GitHub (Jul 15, 2019): You can use the `CONFIG_FILE` environment variable, which should point to the exact JSON file. The exact line of code: https://github.com/dani-garcia/bitwarden_rs/blob/05a1137828a69da8ac687127e0ab6ae88c37a348/src/config.rs#L14
Author
Owner

@MrMEEE commented on GitHub (Jul 15, 2019):

Yeah.. I saw that.. but it doesn't seem to work (me anyways):

[bitwarden@aptabitw01 bin]$ CONFIG_FILE=/opt/bitwarden-rs/server/conf/bitwarden-rs.conf ./bitwarden_rs 
/--------------------------------------------------------------------\
|                       Starting Bitwarden_RS                        |
|                       Version 1.9.1-05a11378                       |
|--------------------------------------------------------------------|
| This is an *unofficial* Bitwarden implementation, DO NOT use the   |
| official channels to report bugs/features, regardless of client.   |
| Report URL: https://github.com/dani-garcia/bitwarden_rs/issues/new |
\--------------------------------------------------------------------/

thread 'main' panicked at 'Can't connect to DB: InvalidConnectionUrl("MySQL connection URLs must be in the form `mysql://[[user]:[password]@]host[:port][/database]`")', src/libcore/result.rs:1051:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
[bitwarden@aptabitw01 bin]$ ls -la /opt/bitwarden-rs/server/conf/bitwarden-rs.conf
-rw-r--r--. 1 bitwarden bitwarden 6185 15 jul 20:22 /opt/bitwarden-rs/server/conf/bitwarden-rs.conf

If I rename the file to .env and put it in the same folder or do a symlink with the name of .env, it works

<!-- gh-comment-id:511533464 --> @MrMEEE commented on GitHub (Jul 15, 2019): Yeah.. I saw that.. but it doesn't seem to work (me anyways): ``` [bitwarden@aptabitw01 bin]$ CONFIG_FILE=/opt/bitwarden-rs/server/conf/bitwarden-rs.conf ./bitwarden_rs /--------------------------------------------------------------------\ | Starting Bitwarden_RS | | Version 1.9.1-05a11378 | |--------------------------------------------------------------------| | This is an *unofficial* Bitwarden implementation, DO NOT use the | | official channels to report bugs/features, regardless of client. | | Report URL: https://github.com/dani-garcia/bitwarden_rs/issues/new | \--------------------------------------------------------------------/ thread 'main' panicked at 'Can't connect to DB: InvalidConnectionUrl("MySQL connection URLs must be in the form `mysql://[[user]:[password]@]host[:port][/database]`")', src/libcore/result.rs:1051:5 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace. [bitwarden@aptabitw01 bin]$ ls -la /opt/bitwarden-rs/server/conf/bitwarden-rs.conf -rw-r--r--. 1 bitwarden bitwarden 6185 15 jul 20:22 /opt/bitwarden-rs/server/conf/bitwarden-rs.conf ``` If I rename the file to .env and put it in the same folder or do a symlink with the name of .env, it works
Author
Owner

@dani-garcia commented on GitHub (Jul 15, 2019):

The .env file is only read from the current directory. The config file is another method and needs to be JSON format.

So what in a .env file you'd configure as:

MY_KEY=value1
OTHER_KEY=value2

in the config JSON file you'd have to do

{
"my_key": "value1",
"other_key": "value2"
}

You could also load the settings into the environment variables yourself (I'm prety sure this works, you might need to add export before every key though):

source /path/to/.env && ./bitwarden_rs
<!-- gh-comment-id:511535935 --> @dani-garcia commented on GitHub (Jul 15, 2019): The `.env` file is only read from the current directory. The config file is another method and needs to be JSON format. So what in a .env file you'd configure as: ```env MY_KEY=value1 OTHER_KEY=value2 ``` in the config JSON file you'd have to do ```json { "my_key": "value1", "other_key": "value2" } ``` You could also load the settings into the environment variables yourself (I'm prety sure this works, you might need to add `export ` before every key though): ```sh source /path/to/.env && ./bitwarden_rs ```
Author
Owner

@mqus commented on GitHub (Jul 15, 2019):

If you use systemd, you can also set the .env file in your .service file with

EnvironmentFile=/etc/bitwarden_rs.env

I already did that for archlinux, you can see the resulting service file in the wiki

<!-- gh-comment-id:511543661 --> @mqus commented on GitHub (Jul 15, 2019): If you use systemd, you can also set the .env file in your .service file with ``` EnvironmentFile=/etc/bitwarden_rs.env ``` I already did that for archlinux, you can see the resulting service file [in the wiki](https://github.com/dani-garcia/bitwarden_rs/wiki/Setup-as-a-systemd-service)
Author
Owner

@MrMEEE commented on GitHub (Jul 15, 2019):

Cool..thanks

<!-- gh-comment-id:511559505 --> @MrMEEE commented on GitHub (Jul 15, 2019): Cool..thanks
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/vaultwarden#339
No description provided.