[Solved] Nextcloud configuration with environment variables

In certain environments like on Docker, Kubernetes or OpenShift applications usually get configured using environment variables. These apps follow The Twelve-Factor App principles.

Is it possible to configure certain settings in Nextcloud like database parameters using environment variables?

1 Like

Does config.php fit your description?
https://docs.nextcloud.com/server/12/admin_manual/configuration_server/config_sample_php_parameters.html

Not really, I’m not talking about a configuration file but about Environment Variables.

I don’t know for sure, but I’m not aware of any environment variables that Nextcloud uses. It just uses a config file like you see above. So apparently Nextcloud fails factor 3 of the twelve-factor app principles. :astonished:

Found the solution: https://github.com/nextcloud/server/pull/3966

1 Like

Where are all environment variables documented? I would like to setup the complete docker nextcloud environment about environment variables.

For docker images, usually you can get that information right on docker hub. Here’s the link to the nextcloud image:

https://hub.docker.com/_/nextcloud

1 Like

Yes. that’s true, but I don’t want only define environment variables for the installation process. I am looking for environment variables which are equivalent with the settings I can define in the config.php file.

I don’t think Nextcloud uses environment variables, it relies on config.php. Maybe there’s a way to map config.php to point to env vars?

I wish I had found this before I setup my kubernetes deploy to copy the config.php from S3 in an initContainer. :+1:

Oops I was wrong, after reviewing that pull request referenced from a couple years ago, it looks like you can just take any key you can use in config.php and prefix it with NC_ as an environment variable, and that overrides whatever is in config.php. I’m not sure if that’s in the documentation anywhere but that’s what the code does.

1 Like

You know if it’s possible to configure an array with environment variables?

Example with trusted_proxies?

I’m deploying Nextcloud 24.0.5 using helm chart. Its possible define config.php labels with configmap? Its a better way to do this i think.

thanks!
it help a lot!

Hello folks!
Is it possible to configure the trusted_proxies through environment variables?

If you’re referring to with the micro-services Docker image, than yes. See the docs: GitHub - nextcloud/docker: ⛴ Docker image of Nextcloud

This is an old topic, but I stumbled upon it and while it says it’s solved, the linked PR doesn’t give a concrete example which I think would be useful, though.

In general the configuration via env vars seems to be possible but inconsistent before that PR.
For instance you can indeed configure the data directory like this:

NEXTCLOUD_DATA_DIR=/…

Now the trusted_proxies?
Surely that would be NEXTCLOUD_TRUSTED_PROXIES. But no, it’s just TRUSTED_PROXIES.

But as implemented in the PR linked by @tobru, You can indeed just put everything into the environment prefixed with NC_! Thanks for the hint.
For instance I added the following to get rid of some warnings in the administration:

NC_maintenance_window_start=1
NC_default_phone_region=DE

Does this work for arrays as well?
For example, how would you define the following config?:

        "app_install_overwrite": [
            "htmlviewer",
            "epubviewer",
            "ncdownloader",
            "transfer",
            "extract",
            "files_archive",
            "files_scripts"
        ],

Should it be comma-separated?

NC_app_install_overwrite="htmlviewer,epubviewer,ncdownloader,transfer,extract,files_archive,files_scripts"

Or something else?

Edit: the answer is that you can’t. All defined NC_* env values are treated as raw strings and used as is: server/lib/private/Config.php at 6669c495d4ef9b702d044a8a766bb7d11d807e1b · nextcloud/server · GitHub

I created an issue for that: Overridden `config.php` variables via `NC_*` cannot be arrays (or anything else than strings) · Issue #49658 · nextcloud/server · GitHub