17th December 2015

Drupal 7 Environment Dependency Management with the Master Module

John Ennew
Technical Director

The Master Module is a solution to the problem of ensuring that your site has the correct modules in each environment.

In a settings file, you specify a list of base modules which all environments use. You then specify for each environment which extra modules it needs.

At Deeson we have a very specific way of managing our settings.php file which can be seen here. This approach allows us to have a file at sites/all/conf/master.settings.inc which contains our master configuration which specifies which modules should be enabled on each environment.  Our appraoch will also have defined a PHP constant of SETTINGS_ENVIRONMENT which will be either localdevtest or prod depending on which environment the site is running on and use this to define the correct list of modules for the site.  

Note that this is slightly different to how the documentation for Master module is described which uses its own definition of each environment as a scope. By using our standard SETTINGS_ENVIRONMENT constant we can define per environment settings for the Master module in the same was as we would do for any other module in our settings file.

A simple master.settings.inc is described below:


With the Master module settings in place, you can now use the following drush commands:

drush master-status

This drush master-status command lists all the modules on your site in the following sections:

Required modules: Modules which are presently not defined in your master settings file for the current environment but would be enabled because there are dependencies on them because of other modules which are required in your current environment. They probably should be defined in your settings file for this environment.

Missing modules: These are modules which should be enabled in your current environment but are not.

Redundant modules: These are modules which are enabled in your current environment but should not be.

Uninstall modules: These are modules which are presently disabled and not required in your current environment and should be uninstalled.

drush master-execute

The drush master-execute command will enable required and missing modules, and disable and uninstall redundant modules.  It will prompt you before taking action if used without the -y option.  

If you are using some form of continuous integration then this can be really helpful since you can use it to ensure all modules which should be enabled are in a given environment. When you add a new module to the site, you just have to put it into the right environment section of your master settings file and the Master module will take care of the rest.