I created a Drupal 7 feature and usually I would enable it with Drush, but someone suggested that I enable it with an update hook (which I assume means it gets enabled on updb or update.php).

I saw this discussion on enabling modules programmatically How do I programmatically install and enable a module?, but it blithely skips over where to write the code. Does it go somewhere in the installation profile? Does it have to be called from another custom module that is already enabled?

I'm actually an experienced Drupaler that has somehow managed to miss this one crucial lesson, I've just been using Drush to enable modules but I want to do this the best way.

  • @PatrickMan – Yes, to have code inside a hook_update_N triggered, it needs to be placed in an enabled module.
    – leymannx
    Sep 12, 2019 at 19:14
  • This has been very helpful. So if there are other features on the site that have been enabled with update hooks (by other developers), where am I likely to find those update hooks. In a non-feature custom module? In the installation profile? Thanks! Sep 12, 2019 at 19:26
  • 1
    @PatrickMan – Yepp, I'd scan the custom profile's or sites/all/modules/custom or sites/all/modules/features directory for module_enable, just this string. Than you should find it.
    – leymannx
    Sep 12, 2019 at 19:29

1 Answer 1


A feature module is just another module. And you can enable it programmatically using the linked code from another enabled module's hook_update_N placed in this another enabled module's *.install file. This even can be another feature module. Then have this hook fired via drush updb on the command line or by visiting your site's /update.php.

You also could do that from a form submit handler. Or even from a menu callback providing some custom endpoint you can access with cURL for example.

It's safe to use other feature modules' *.install files. Since Features never touches *.module and *.install files during regeneration. So you are free to use them to your needs.

Your Answer

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

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