Problem/Motivation

#2243439: Both file and db configuration storage are said to be default in settings.php corrected the documentation for how to switch from database to file configuration storage.

The intention is to have settings.php document how to toggle this for developers.
But the instructions for what to put in services.yml are not clear.

They read:

/**
 * Active configuration settings.
 *
 * By default, the active configuration is stored in the database in the
 * {config} table. To use a different storage mechanism for the active
 * configuration, do the following prior to installing:
 * - Override the 'bootstrap_config_storage' setting here. It must be set to a
 *   callable that returns an object that implements
 *   \Drupal\Core\Config\StorageInterface.
 * - Override the service definition 'config.storage.active'. Put this
 *   override in a services.yml file in the same directory as settings.php
 *   (definitions in this file will override service definition defaults).
 */
# $settings['bootstrap_config_storage'] = array('Drupal\Core\Config\BootstrapConfigStorageFactory', 'getFileStorage');

Proposed resolution

Document in the settings, or link to a drupal.org documentation page,
for what the services.yml file should contain.

Remaining tasks

  • decide what should be in the services.yml
  • try it to make sure it works
  • make a patch to update the settings.php comment

User interface changes

No.

API changes

No.

Comments

YesCT’s picture

In #2243439-59: Both file and db configuration storage are said to be default in settings.php @vijaycs85 suggests

# sites/default/services.yml

services:
  config.storage.active:
    class: Drupal\Core\Config\FileStorage
    factory_class: Drupal\Core\Config\FileStorageFactory
    factory_method: getActive

YesCT’s picture

in https://gist.github.com/sun/10732324

@sun has

services:
  config.storage:
    class: Drupal\Core\Config\CachedStorage
    arguments: ['@config.storage.active', '@cache.config']
  config.storage.active:
    alias: config.storage.file
sun’s picture

This related issue rewrites the docs a bit and changes the functional config storage service implementation to simplify a custom services.yml definition.

jhodgdon’s picture

I do not think we should modify the documentation here. If someone does not know how to create a service, there is documentation available on the subject, but a settings.php file is not the place to document it.

The most I would say we should do is to link to generic documentation on how to create services.

YesCT’s picture

Yes, at least we should link to where to find more information.
Can we link to a doc that specifically says how to do *this*, maybe as a child of the services doc page (as an example)?

People are going to ask this alot. If the settings tells them to do it this way.

Alternatively, we could link to config_devel module, which I think also provides a way to have config in files.

vijaycs85’s picture

The most I would say we should do is to link to generic documentation on how to create services.

this is very similar to how we override stuff in settings.php that we initially have in different place (like variable). If the plan is to documentation, then it should talk about 'how to override services'

jhodgdon’s picture

Here is my suggestion:

Someone should create a documentation page on drupal.org that explains how to do this, step by step. The steps really are:
a) create a module (mymodule.info.yml file in the mymodule directory, and if we're making a tutorial we should say where to put this directory too)
b) in the module directory, create a file called mymodule.services.yml, with lines as above. I really have no idea whether #1 or #2 is correct.
c) enable the module.
d) uncomment that line in settings.php I guess? is that even necessary?

OK, I really have no idea what the steps are -- this may not be correct. So I suggest that someone write up a page and someone else try to follow the instructions, and iterate until the instructions give the desired result and are clear.

Then we can make a page alias for the page, like drupal.org/config-database/8 or something like that, and patch default.settings.php to point there.

I suggest putting this page as a child of https://www.drupal.org/node/2133171 (services API for 8 section).

Thoughts?

pwolanin’s picture

So, there are several possible ways to set this up - if you want just pure local-dev file based then the one form vijaycs85 would work.

However, it's not something you should ever use in production, so the docs need to be clear.

jhodgdon’s picture

Are you saying that you should never use file-based storage for config in production, period? Or that the form in comment #1 is not OK?

Damien Tournoud’s picture

Is it me or all this is way to advanced to begin with and should really not be in the example settings.php anyway?

jhodgdon’s picture

I'm beginning to think this is the case. If it's not for production and would require understanding of the DIC to program it, I think we should not mention it in settings.php, but document it somewhere else on drupal.org for advanced users only.

cilefen’s picture

jhodgdon: Regarding #9, #1 technically works (ednawig and I tested it) but should not be used in production as described by pwolanin.

#2 does not work currently because the cache.config service is gone.

TomSherlock’s picture

cilefen, pwolanin, if #1 technically works but should not be used in production, which settings should then be used in production?

cilefen’s picture

Try #2.

aschiwi’s picture

Ah, interesting. I have been looking at configuration management all day and was just cleaning up the docs there.

I found something on how to use the file based workflow, but from my work with stBorchert I knew that this was old and it now needed to be enabled first. We found this issue and I just updated the docs there: https://www.drupal.org/node/2416555. Since you were talking about where to put it because people are going to ask, I think it belongs in the CM docs but could be linked from the services docs.

aschiwi’s picture

One thing I am unclear about is the reason behind switching to file based configuration storage, is this recommended at all besides for developer use?

xmacinfo’s picture

File-based = code that can be tracked, transferred and deployed.

For efficiency, though, Drupal 8 will still read the configuration from the database and use the configuration files as the source of the config, before loading them.

cilefen’s picture

@aschiwi It's considered an advanced configuration for those that know what they are doing at this stage.

aschiwi’s picture

Thank you for your replies. I thought deployment-wise we basically only need the staging directory, but I see how it can be of advantage to directly see active config changes in files, without having to export the config.

From what I understand, for Drupal 8 we decided on the database for active storage because it's better for performance and security.

Just to be sure: Do I understand you correctly that I could switch to file storage for my active configuration if I preferred and it wouldn't be a problem for my production system?

cilefen’s picture

@aschiwi I think that if you did you would have significant performance problems because the last I checked, there is a missing caching layer.

aschiwi’s picture

Thank you cilefen :)

vincenzodb’s picture

At this moment ( 8.0.0-beta16 ) to switch to file configuration before install Drupal:

  1. Into settings.php:

    Uncomment
          $settings['bootstrap_config_storage'] = array('Drupal\Core\Config\BootstrapConfigStorageFactory', 'getFileStorage');
         

    then add:

           $config_directories = array(
             CONFIG_ACTIVE_DIRECTORY => 'PATH_OUTSIDE_WEB_ROOT/config/active/',
             CONFIG_STAGING_DIRECTORY => 'PATH_OUTSIDE_WEB_ROOT/config/staging/',
             CONFIG_SYNC_DIRECTORY => 'PATH_OUTSIDE_WEB_ROOT/config/sync/',
            );
         
  2. In the sites/default/services.yml add:
          services:
            config.storage:
              class: Drupal\Core\Config\CachedStorage
              arguments: ['@config.storage.active', '@cache.config']
            config.storage.active:
              class: Drupal\Core\Config\FileStorage
              factory: Drupal\Core\Config\FileStorageFactory::getActive
        
jhodgdon’s picture

Thanks for writing that down @vincenzodb ! So we should either add this to the default.settings.php file as documentation, or we should put it somewhere else (perhaps with a link in default.settings.php to this information, somewhere around the section that talks about config directory settings).

rsullivan’s picture

Disclaimer: I'm Drupal newbie but have >10 years of suffering in the Java Server world.
I am trying to help a charitable organisation move to Drupal. File based configuration will be essential since I need to share the config work.

I first installed Drupal 8 RC3 as a normal person would via the web installer. After the installation succeeded I realized I needed to wipe everything and start over in order to get the file based configuration.

I took the config as described by vincenzodb (which seems to be the same as described in "Drupal 8 Configuration Management" (PACKT Books).

The problem is that the config shown by both of these sources (and everything else I could find) seems to be out of date (for example there now seems to be just one "sync" directory instead of "active" and "staging".

Could you please update the documentation (BTW comments in settings.php still refers to "active" and "staging").

I disagree with some of the comments here that basically say "this is rocket science stuff, anyone who can't inject services shouldn't be shown how to use it). File based configuration should become mainstream so it does need documenting and should somehow be made a reasonably easy to set up at install time or later!

Thanks,
Richard Sullivan

vincenzodb’s picture

@rsullivan
Hi!

Yes, my code is inspired by the PACKT's book but also the code in the ebook is outdated but it's 'normal' for a book writed during Drupal 8 Development.

So, yes, recently 'sync' dir has 'appired' and I've updated my comment, thanks

joachim’s picture

         CONFIG_ACTIVE_DIRECTORY => 'PATH_OUTSIDE_WEB_ROOT/config/active/',
         CONFIG_STAGING_DIRECTORY => 'PATH_OUTSIDE_WEB_ROOT/config/staging/',
         CONFIG_SYNC_DIRECTORY => 'PATH_OUTSIDE_WEB_ROOT/config/sync/',

What are the reasons for this needing to be outside the webroot?

Coming from a Features-based workflow on D7, Features modules were in the webroot, and thus committed to the site codebase.

rsullivan’s picture

I've tried the config from vincenzodb on RC3 and RC4. Both of these give the same exception "...The service definition "config.storage.active" does not exist. in Symfony\Component\DependencyInjection\ContainerBuilder->getDefinition() ...". See end of post for full text.
Beta2 gave me some other apparently unrelated obscure errors that I don't really feel like spending time on now.

Attached you can find a screenshot of the most import config files and directories, text file containing the exception text etc. - all of that from RC3 except for a Drupal8_beta2_installOutput.pdf which shows errors reported by the beta2 installer.

I've put up a test environment on koding.com (if you don't know koding.com basically it is Linux VM with a nice terminal and IDE interface both of which run in your web browser).
If anyone is interested I can power up the VM and share access to it.

Any ideas ?
Thanks,
Richard

Additional uncaught exception thrown while handling exception.

Original

Symfony\Component\DependencyInjection\Exception\InvalidArgumentException: The service definition "config.storage.active" does not exist. in Symfony\Component\DependencyInjection\ContainerBuilder->getDefinition() (line 868 of /home/rsullivan/Web/drupal/vendor/symfony/dependency-injection/ContainerBuilder.php).

Symfony\Component\DependencyInjection\ContainerBuilder->getDefinition('config.storage.active')
Drupal\Component\DependencyInjection\Dumper\OptimizedPhpArrayDumper->getReferenceCall('config.storage.active', Object)
Drupal\Component\DependencyInjection\Dumper\OptimizedPhpArrayDumper->dumpValue(Object)
Drupal\Component\DependencyInjection\Dumper\OptimizedPhpArrayDumper->prepareParameters(Array, 1)
Drupal\Component\DependencyInjection\Dumper\OptimizedPhpArrayDumper->prepareParameters(Array, 1)
Drupal\Component\DependencyInjection\Dumper\OptimizedPhpArrayDumper->prepareParameters(Array, 1)
Drupal\Component\DependencyInjection\Dumper\OptimizedPhpArrayDumper->prepareParameters(Array, 1)
Drupal\Component\DependencyInjection\Dumper\OptimizedPhpArrayDumper->getParameters()
Drupal\Component\DependencyInjection\Dumper\OptimizedPhpArrayDumper->getArray()
Drupal\Core\DrupalKernel->initializeContainer()
Drupal\Core\Installer\InstallerKernel->initializeContainer()
Drupal\Core\DrupalKernel->boot()
install_begin_request(Object, Array)
install_drupal(Object)
Additional

Symfony\Component\DependencyInjection\Exception\InvalidArgumentException: The service definition "theme.manager" does not exist. in Symfony\Component\DependencyInjection\ContainerBuilder->getDefinition() (line 868 of /home/rsullivan/Web/drupal/vendor/symfony/dependency-injection/ContainerBuilder.php).

Symfony\Component\DependencyInjection\ContainerBuilder->getDefinition('theme.manager')
Symfony\Component\DependencyInjection\ContainerBuilder->get('theme.manager')
Drupal::theme()
_drupal_maintenance_theme()
drupal_maintenance_theme()
install_display_output(Array, Array, Array)
_drupal_log_error(Array, 1)
_drupal_exception_handler(Object)
vincenzodb’s picture

@rsullivan
add

services:
        config.storage:
          class: Drupal\Core\Config\CachedStorage
          arguments: ['@config.storage.active', '@cache.config']
        config.storage.active:
          class: Drupal\Core\Config\FileStorage
          factory: Drupal\Core\Config\FileStorageFactory::getActive

at the end of the services.yml file at 'root' level of the file... more specific: outside 'parameters'

rsullivan’s picture

Thanks vincenzo - you have saved my bacon!
I think it would be great to have this snippet embedded as a comment block in the default.services.yml - would probably save a lot more stupid questions like mine !
Richard

vincenzodb’s picture

@rsullivan
You're welcome :)

Yes, isn't symple without a good documentation. The `services.yml` file it's a core configuration of the services and their parameters of a single Drupal installation and can contain parameters of the common services declared by the Drupal core and others modules and can override them (like "our" `config.storage` in this case).

Create a comment snippet for each service isn't useful IMHO but I've created a little sandbox project (here https://www.drupal.org/sandbox/vincenzodb/2609296) that can help with a first Drupal8 installation. Feel free to try it and any feedback (use the project's issues please) are very apprecciated.

vincenzodb’s picture

@joachim
Feature module (in Drupal 8) organize the configuration files (don't contain them) in Modules and groups Modules inside Profiles if it's needed. Isn't important where are placed the files and if we place them outside webroot is more safe

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

defconjuan’s picture

Has anyone trying going the reverse direction?

I have a D8 site with file-based config successfully enabled and working. I'd like to go back to database config storage but it doesn't seem to be as simple as undoing these edits to the settings.php and services.yml file (even when combined with a "drush cim sync").

vijaycs85’s picture

#33: @defconjuan: one of the option is to export the config and import them using https://www.drupal.org/project/config_installer

defconjuan’s picture

@vijaycs85, so for workflow, you're thinking:

  1. export config
  2. backup database and files
  3. wipe database
  4. remove file-based config entries from settings.php and services.yml
  5. add config_installer to the codebase
  6. install new site using config_installer

And then what, re-import the files and database to restore the content?

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

michaellenahan’s picture

FileSize
849 bytes

Maybe I am not seeing the full picture, if so, apologies :)

To fulfill the purpose of this issue "Document how to toggle to file configuration storage in settings.php" - maybe it is now enough to simply document it in default.settings.php, as suggested by jhodgdon in #7 and #23 ?

We now also have a nice documentation page we can point to:
https://www.drupal.org/docs/8/configuration-management/changing-the-stor...

EDIT: FACEPALM. I got this wrong. I just read the issue title again. "Document how to toggle to file configuration storage in settings.php" - what I want to document is the storage location of the configuration sync directory NOT how to use file configuration storage as Drupal's active configuration storage mechanism. The documentation I want is already in default.settings.php and was added in http://cgit.drupalcode.org/drupal/commit/?id=921cf91