Composer is a dependency manager for PHP packages. It allows us to download the tools needed for our projects, and this is all defined in composer.json files. We can run "composer install" to install libraries listed in these files or "composer update" to pull in updated libraries. We can also run "composer require project/name" to download a new dependency into our project.

We typically don't use Drupal alone, but with contributed modules and themes. Composer can help you manage the dependencies between these projects and facilitate updates. It is important to note that the role of Composer is to manage our codebase, it has nothing to do with enabling/disabling modules or themes in our Drupal installation, it's just to assure we have the packages needed and manage the dependencies.

This guide assumes that you already have your stack setup to add Drupal in. Some alternatives are using Visual Studio Code and Pantheon (it will get the code automatically), a custom LAMP stack, or even a setup using Lando, Docksal or DDEV.

Installation of Composer

First, we need to ensure that we have Composer installed.

  1. Run the following in the command line to see if Composer is already installed:composer -V
  2. You will either see the version of Composer that you have or a message that it is not installed.
  3. If you see that Composer is not installed, go to https://getcomposer.org and follow the instructions on the Download page.
  4. If you’re on Mac and you use Homebrew, you can use the following command to install composer: brew install composer