By liam morland on
In Drupal 8+, how do I set configuration in settings.local.php? For example, the site name can be retrieved like this:
$site_name = \Drupal::config('system.site')->get('name');
I ought to be able to set this value in settings.local.php something like this:
$config['system.site']['name'] = 'My Site Name';
This doesn't work. How do I do this?
Comments
That looks correct. Do other
That looks correct. Do other config settings there work?
Is your settings.local.php file actually being used? Have you uncommented the relevant lines at the end of settings.php?
Verified the command by placing it in settings.php
It does require a cache rebuild.
Then moved it to settings.local and activated calling it from settings.php. Rebuild of cache again, it works for me.
Thanks, both. It does work
Thanks, both. It does work after a cache clear. That is different from D7 where a cache clear was not needed.
The other strange thing is that the value is not showing up in
drush config:get. I still get the old value there.Edit: This is explained in Configuration override system.
$settings and $config
I couldn't figure out why this didn't work in my
settings.php:$settings['system.site']['name'] = 'STAGING';But this does:
$config['system.site']['name'] = 'STAGING';From $conf to $config and $settings in Drupal 8 explains the differences between
$settingsand$config.EDIT aug 2025: The web site https://anavarre.net/from-conf-to-config-and-settings-in-drupal-8/ seems to be down, but this is the content from another copy: