Posted on Tue, 09/04/2018 - 11:11
Drupal 8 workflow - Git submodules, Composer and DeployHQ

After enormous amounts of frustration, I've finally worked out a recipe for setting up Drupal development websites working with composer, git and deployHQ - the submodules were the fly in the ointment, here is how to work with them.

First, create a new Drupal web development project using composer

>$ composer create-project drupal-composer/drupal-project:8.x-dev my_site_name_dir --stability dev --no-interaction

Next, rename web to public_html - so it plays nicely with cPanel

edit composer.json file - swap this in to replace the extras section renaming web to public_html

 "extra": {
        "installer-paths": {
            "public_html/core": ["type:drupal-core"],
            "public_html/libraries/{$name}": ["type:drupal-library"],
            "public_html/modules/contrib/{$name}": ["type:drupal-module"],
            "public_html/profiles/contrib/{$name}": ["type:drupal-profile"],
            "public_html/themes/contrib/{$name}": ["type:drupal-theme"],
            "drush/Commands/{$name}": ["type:drupal-drush"]

rename the web directory to public_html

>$ composer update

We then get some doctrine errors because of our php version, this fixes them - add these to require section of composer.json

"require": {
"php": ">=5.5.9",
"doctrine/doctrine-bundle": "^1.6",
"doctrine/orm": "2.5.6",
"doctrine/annotations": "1.4.*",
"doctrine/dbal": "2.5.4",
>$ composer update
Next, make a new git repository for your project. You can now check all the entries in the index which are referencing submodules:

>$ git ls-files --stage | grep 160000

This should give you a list of files something like this (extra info removed)


now do this for each module found:

git submodule add vendor/behat/mink
git submodule add vendor/drush/drush
git submodule add public_html/modules/contrib/googleanalytics

you can find the git location from the config file in the modules repo

then run

>$ git submodule sync # update URLs of submodules
>$ git submodule update --init # install new submodules and update state

I now have a .gitmodules file with these lines in it

[submodule "vendor/behat/mink"]
path = vendor/behat/mink
[submodule "vendor/drush/drush"]
path = vendor/drush/drush
[submodule "public_html/modules/contrib/googleanalytics"]
path = public_html/modules/contrib/googleanalytics

And my main git repo now has these lines added to the config file

[submodule "vendor/behat/mink"]
active = true
[submodule "vendor/drush/drush"]
active = true
[submodule "public_html/modules/contrib/googleanalytics"]
active = true

All, quite fiddly and fragile but it seems to work.

Now you can push and deploy and all should go smoothly! Next time you run composer update it should all just work. Check out some of our CMS website design portfolio to see some websites that we have created using these techniques.

Drupal development can be tough and it's not always the obvious areas that trip you up.


Add new comment

Request a Free Quotation

Your Name