Skip to main content
Home Home

Join

  • Get in touch

Main navigation

  • Blog
    • Tracking changes on field level on entities
  • Team
  • Home
  • Blog
  • Drupal 8 Composer 101 tutorial

Drupal 8 Composer 101 tutorial

Tamer Zoubi, Drupal expert
by Tamer Zoubi
Founder, Partner & CTO
18 Jul 2017
This tutorial is for managing Drupal (>=8.1) with composer.
 
What is composer?
For getting started with Composer in general, please visit the offical documentation.
 
Git practices:
put /vendor in .gitignore
put /modules/contrib in .gitignore
 

Install site:

composer install
 
Modules:
Use official Drupal package repository: https://www.drupal.org/node/2718229
composer config repositories.drupal composer https://packages.drupal.org/8
 
ALWAYS install modules using composer. Forget about Drush or even manual download!!
composer require drupal/{module_name}:{module_version}
Where {module_version} example:

8.x-1.1 => 1.1

8.x-2.2.0 => 2.2.0

We can support updates by saying 1.* which means next time you make composer install or update it will update to newer minor version if exists, but won't update to 2.x.
 
Dont's:
Don't use https://packagist.drupal-composer.org/ as this one is deprecated.
Don't install module manually or through Drush.
Don't change anything in modules source code. Patch it and add patch through composer.json.
Don't use composer manager module, this is no more needed as of Drupal 8.1
 
Uninstall a module:
 
Always uninstall a module in this 2 step way:
drush pm-uninstall {module_name}
composer remove drupal/{module_name}

 

Other:

You can always see latest library and module versions installed in composer.lock file.
 
Deploying modules to other devs or production:
Now you added a module locally through composer and want to push it? Since modules are now ignored in git, only thing that will be pushed is depenency in composer.json. Therefore to deploy the module, each developer will need to rebuild its dependencies using 
"composer install".
Drupal configuration manager will take care if the module is enabled or not. However order must be respected so you should import new configuration only after composer install is run, otherwise you might get a error.
 
So good practice after git pull is:
 
composer install
drush cim
drush cr
 
Drupal 8 composer starterkit:
https://bitbucket.org/websolutionshr/drupal-8-ws-starterkit 
 
FAQ:
 
Q:What if I downloaded a module manually or through Drush?
A: Just re-add it using composer require drupal/{module_name}:{module_version}
Make sure its in modules/contrib folder.
 
Share
Tags
composer
Drupal 8
drush
Planet Drupal
starterkit

LOOKING FOR A DIGITAL EXPERIENCE?

Looking for a digital experience built on Drupal?
Get in touch with Drupal experts!

Get in touch

Croatia

Svetice 21
10000 Zagreb
hello@ws.agency
+385 1 3445 884

USA

Atlanta
+1 404 549 5896
Home

Footer menu

  • Privacy
  • Sitemap
  • Blog
  • Careers
  • Get in touch

© 2022 Websolutions Agency. All Rights Reserved.