Did you know anysetting.config.php

I would like to share for those who did not know.

you can configure your Nextcloud installation with seperate config(s).php

create a file setting-name.config.php starting with

<?php
$CONFIG = array (

);

and put your settings after ( and before );

For example you have your default config.php that contain all your settings. To make your config.php clearer you can take all the database settings and put them in a separate config names database.config.php

the file database.config.php would look like

<?php
$CONFIG = array (
  'dbtype' => 'mysql',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'dbuser' => 'DB_USERNAME',
  'dbpassword' => 'DB_PASSWORD',
  'mysql.utf8mb4' => true,
);

Remove these copied settings from config.php

another example: redis.config.php

<?php
$CONFIG = array (
  'filelocking.enabled' => true,
  'memcache.locking' => '\\OC\\Memcache\\Redis',
  'memcache.local' => '\\OC\\Memcache\\Redis',
  'redis' =>
  array (
    'host' => 'localhost',
    'port' => 6379,
  ),
);

I give you one more for mail.config.php

<?php
$CONFIG = array (
  'mail_smtpmode' => 'sendmail',
  'mail_from_address' => 'cloud',
  'mail_domain' => 'domain.tld',
  'app.mail.imaplog.enabled' => 'true',
  'mail_smtpauthtype' => 'LOGIN',
  'mail_smtphost' => 'smtp.domain.tld',
  'mail_smtpport' => '587',
  'mail_smtpsecure' => 'tls',
  'mail_smtpauth' => 1,
  'mail_smtpname' => 'MAIL_USERNAME',
  'mail_smtppassword' => 'MAIL_PASSWORD',
);

custom.config.php

<?php
$CONFIG = array (
   'theme' => 'Theme1',
   'default_phone_region' => 'NL',
   'defaultapp' => 'files',
   'knowledgebaseenabled' => false,
   'simpleSignUpLink.shown' => false,
   'profile.enabled' => true,
   'login_form_autocomplete' => false,
);

Any file located in NC_Installation_dir/config/ ending with .config.php will be merged and stored as config.php

I found this very useful and hope others may have use of it too.

source : Admin Manual

10 Likes

Thanks for giving examples to this feature - I really missed within the admin manual :+1:

Btw, is there a list of each and every configuration parameter there is?

There is a config.sample.php in your config directory. I’m not sure if it really covers all parameters, but you can find some explanation for them there, too.

If I understand correctly, I can take all e.g. mailparameters out of config.php and put them into mail.config.php and merge them into a new config.php .
In other words, if I need to modify one of the mail parameters, I need to do this on both places. Is that correct ?

The settings in the custom files take priority over the ones in config.php. You can either remove the no longer used bits from your config.php (the mail settings in your case) or leave them and they’ll be overwritten by whatever you have in mail.config.php.

The docs linked to explain it:

Nextcloud supports loading configuration parameters from multiple files. You can add arbitrary files ending with .config.php in the config/ directory, for example you could place your email server configuration in email.config.php. This allows you to easily create and manage custom configurations, or to divide a large complex configuration file into a set of smaller files. These custom files are not overwritten by Nextcloud, and the values in these files take precedence over config.php.

OKAY, so if I update the SMTP password in the web interface , it will update the config.php file.
But the mail.config.php still contains the old password which takes precedence over the I just changed.
I’ll adjust. Thank U

Even though custom config files take priority over the settings in config.php, they seem to not only to get overwritten, they also get changend.

I will try to explain:
I have a custom config file named domains.config.php, with settings specifically for differnt domains, just like so.
Eventually I want to have the default settings in config.php not changed, but everytime I edit my custom config file or update my Nextcloud instance the settings specifically for on domain from domains.config.php gets written in config.php.

Is there a way to prevent this without changing permissions on config.php?

I noticed this a long time ago and thought it was a bug. However, my issue was immediately closed. “It is designed to do so, not a bug”

Now I handle it in my scripts in a way that takes this “design” into account.
This means that, at least for me, it no longer loses any functionality, although from other considerations I think it is extremely undesirable behavior.

If you want to set a setting that is stored in config/some.config.php with
./occ config:system:set $some_value
… it will simply be adopted but then have no effect. So it’s not transparent. No warning.


Much luck,
ernolf

1 Like

Thank you for the quick reply! I already spent some time searching the forums but couldn’t find your bug report. Really strange behaviour though.