Features: Moving Site Configuration to Code

Last updated on
21 November 2016

Drupal 7 will no longer be supported after January 5, 2025. Learn more and find resources for Drupal 7 sites

Consider this scenario: you have created a custom content type on your local development server with several core and contributed field types specific to your application. Additionally, you have meticulously configured specific views for this content type, and created a custom user role that provides permission to add, edit, and delete the content of this content type.

At this point, the content type lives in the database, not in code, so moving it to a remote server without overwriting the remote database presents quite a challenge. There are typically three ways to accomplish this:

  1. Manually: You could open up your local site in one browser tab and your remote site in another tab, and switching back and forth between the two tabs, you could manually re-create each of the fields of your local content type into a new content type on your remote site. Working through the frontend would most likely prevent you from accidentally overwriting critical database configurations, but the inconvenience of this approach outweighs the benefits. Aside from being time consuming, this method would require you to download and enable each of the dependency modules (Address Field, Link, Views, etc.). You would then need to rebuild the custom view you created on your local site and re-create the roles and permissions associated with your content type. While manual migration can be an option in some simple use cases, for more complex cases it can be a lot unnecessary repeated work.
  2. Manual Import/Export: Some of the modules, such as views, allow for importing and exporting through the UI. This would be a much better, faster and more precise option than redoing everything manually. The downside of this method is that there is no way to track the migration and therefore no way to track changes.
  3. Export the configuration to Code: Using the Features module, you can package all of the custom fields, configurations, dependencies and permissions associated with your content type into a single package. Because Features essentially create a new module, all of the information is stored in code, and can therefore be used in conjunction with a version control system like Git or SVN. This makes features a great way to manage changes between your development, staging and production sites.

Help improve this page

Page status: No known problems

You can: