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
Comment #1
yesct commentedIn #2243439-59: Both file and db configuration storage are said to be default in settings.php @vijaycs85 suggests
Comment #2
yesct commentedin https://gist.github.com/sun/10732324
@sun has
Comment #3
sunThis related issue rewrites the docs a bit and changes the functional config storage service implementation to simplify a custom services.yml definition.
Comment #4
jhodgdonI 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.
Comment #5
yesct commentedYes, 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.
Comment #6
vijaycs85this 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'
Comment #7
jhodgdonHere 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?
Comment #8
pwolanin commentedSo, 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.
Comment #9
jhodgdonAre 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?
Comment #10
damien tournoud commentedIs it me or all this is way to advanced to begin with and should really not be in the example settings.php anyway?
Comment #11
jhodgdonI'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.
Comment #12
cilefen commentedjhodgdon: 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.
Comment #13
tomsherlock commentedcilefen, pwolanin, if #1 technically works but should not be used in production, which settings should then be used in production?
Comment #14
cilefen commentedTry #2.
Comment #15
aschiwi commentedAh, 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.
Comment #16
aschiwi commentedOne thing I am unclear about is the reason behind switching to file based configuration storage, is this recommended at all besides for developer use?
Comment #17
xmacinfoFile-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.
Comment #18
cilefen commented@aschiwi It's considered an advanced configuration for those that know what they are doing at this stage.
Comment #19
aschiwi commentedThank 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?
Comment #20
cilefen commented@aschiwi I think that if you did you would have significant performance problems because the last I checked, there is a missing caching layer.
Comment #21
aschiwi commentedThank you cilefen :)
Comment #22
vincenzodb commentedAt this moment ( 8.0.0-beta16 ) to switch to file configuration before install Drupal:
Uncomment
then add:
Comment #23
jhodgdonThanks 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).
Comment #24
rsullivan commentedDisclaimer: 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
Comment #25
vincenzodb commented@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
Comment #26
joachim commentedWhat 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.
Comment #27
rsullivan commentedI'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
Comment #28
vincenzodb commented@rsullivan
add
at the end of the services.yml file at 'root' level of the file... more specific: outside 'parameters'
Comment #29
rsullivan commentedThanks 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
Comment #30
vincenzodb commented@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.
Comment #31
vincenzodb commented@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
Comment #33
defconjuan commentedHas 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").
Comment #34
vijaycs85#33: @defconjuan: one of the option is to export the config and import them using https://www.drupal.org/project/config_installer
Comment #35
defconjuan commented@vijaycs85, so for workflow, you're thinking:
And then what, re-import the files and database to restore the content?
Comment #38
michaellenahan commentedMaybe 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
Comment #44
vistree commentedHi all, maybe a stupid question: but, are there any disadvantages in using configuration storage from file system? Is this as stable as storing the config in database? Normally I would expect loading from file system being quicker then loading from database?!
Plus: does this still work with Drupal 9?
Comment #45
cilefen commentedSee #2161591: Change default active config from file storage to DB storage for that discussion.
Comment #46
quietone commentedThe settings of the config directory has changed since this issue was created. It was all done in #2980712: Define config directory in settings and that work addresses this problem. The extra documentation is no longer needed and the documentation in settings.php is sufficient. I just tested to be sure.
Therefore, closing as outdated. If this is incorrect reopen the issue, by setting the status to 'Active', and add a comment explaining what still needs to be done.
Thanks!