It is a bit confusing to understand the difference in State API and Config API in Drupal 8. I went through the documentation of both on drupal.org but it is not clear to me yet.

Do we define both State config and Config variables in config/install directory? And How are they both distinguished?

  • 4
    State is environment-specific - the stuff you don't push around your environments. For example the last time cron ran is specific to an environment - that's state. The list of entity types available to a site is global to all instances of that site, and so is regarded as config
    – Clive
    Commented Sep 25, 2018 at 7:53
  • 2
    Clive covered it all really, but to directly answer your question, no you don't add both State and Config to the config/install directory. There are no .yml files for State values (as state is never meant to be moved between environments). Only config files go into config/install.
    – Jaypan
    Commented Sep 26, 2018 at 8:24

1 Answer 1


Configuration is a place to store information that you want to synchronize from development to production. This information is often created during site building and is not typically generated by regular users during normal site operation.

You should use the State API, not Configuration API, for storing local variables that shouldn't travel between instances.

The State API provides a place for developers to store information about the system's state.

State information differs from configuration in the following ways:

  • It is specific to an individual environment.
  • You will never deploy to deploy it between environments.
  • Configuration is stored in the database, and can be exported to files (allowing migration). State is stored in the database, and cannot be exported.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.