Composer

Composer is the PHP dependency manager that downloads and updates Drupal core, modules, themes and libraries from a list in composer.json.

Learn DrupalDrupal glossary Last updated

Composer is the dependency manager for PHP. A Drupal project lists the packages it needs in a file called composer.json, and Composer downloads them together with the packages they depend on: Drupal core, contributed modules and themes, and libraries such as Drush. It installs everything per project, not on the whole server.

How Composer works in a Drupal project

Three files and folders matter:

  • composer.json lists what you ask for. Its require key maps package names to version constraints; require-dev holds tools used only in development.
  • composer.lock records the exact versions that Composer picked. Commit it, so every environment gets the same code.
  • vendor holds the downloaded third-party code. Composer also writes vendor/autoload.php there, which loads the classes.

Drupal's recommended project template keeps a web directory as the public document root. The vendor directory and the project files stay outside it. Modules and themes from Drupal.org arrive through the Drupal.org Composer endpoint, packages.drupal.org, and the installer-paths setting sends them to the right folders.

Version constraints

A constraint says which versions are acceptable. The caret is the usual choice: ^1.2.3 means at least 1.2.3 and below 2.0.0. The tilde is stricter: ~1.2.3 means at least 1.2.3 and below 1.3.0. Below version 1.0 the caret also narrows, so ^0.3 stays below 0.4.0.

Commands you will use

CommandWhat it does
composer require drupal/tokenAdds a package to composer.json and installs it.
composer remove drupal/tokenRemoves a package from composer.json and uninstalls it.
composer installInstalls the versions in composer.lock.
composer updateResolves the newest allowed versions and rewrites the lock file.
composer outdatedLists installed packages that have newer versions.
composer auditChecks installed packages against security advisories.
composer whyShows which packages depend on a given package.
composer validateChecks that composer.json is valid and the lock file is current.

The require, remove, install and update commands accept --dry-run to preview a change. Install and update also accept --no-dev to skip development packages.

Example: from new site to first update

composer create-project drupal/recommended-project my_site_name
        cd my_site_name
        composer require drush/drush
        composer require drupal/token
        composer update "drupal/core-*" --with-all-dependencies
        vendor/bin/drush updatedb
        vendor/bin/drush cache:rebuild

The first command builds the site from the recommended template and installs its dependencies. The last three are the core update routine from Drupal.org: update the code with Composer, then let Drush apply database updates and rebuild the cache.

Common mistakes

  • Mixing manual downloads with Composer. Once Composer manages a module, update core with Composer too. A manual core update replaces vendor and removes libraries that contributed modules need.
  • Not committing composer.lock. Without it, two environments can resolve different versions of the same package.
  • Lowering minimum-stability for one pre-release module. Ask for that module with a stability flag instead, for example composer require drupal/field_group:^4.1@alpha.
  • Running composer update on a production server. Update on a development machine, commit the lock file, and run composer install on the server.
  • Ignoring prompts about plugins. Composer plugins run code, and the allow-plugins setting lists which ones may run. In non-interactive mode, a plugin that is not listed makes Composer fail.

For marketing and content teams

When a developer says a module or theme "needs a Composer update", they mean the code behind your site is being changed. Because the lock file records exact versions, a module that works on staging will run the same version on production. Ask for the update to be tested on a staging copy first, especially for security updates that you want live quickly.

With DXPR

DXPR Builder is on Drupal.org and installs the usual way: composer require drupal/dxpr_builder. Its page also lists versioned commands for pre-release builds. See DXPR Builder for what it adds to your editing screens.

Sources

Questions about Composer

composer install installs the exact versions recorded in composer.lock. composer update looks for the newest versions that composer.json allows, writes them to the lock file and installs them. Use update on your development machine and install on servers.

Run composer require drupal/token, replacing token with the project's machine name. Composer updates composer.json, downloads the module and its dependencies, and records the versions. Then enable the module, for example with drush pm:install token.

Yes. Composer's documentation says to commit it, so that everyone on the project, including CI and production, uses the same dependency versions. The vendor directory is normally left out of the repository instead.

Back up the code and database, then run composer update "drupal/core-*" --with-all-dependencies. Add --dry-run first to preview the changes. Afterwards run drush updatedb and drush cache:rebuild, and check the Status report.

The installer-paths setting in composer.json decides. Drupal's guide gives modules/contrib/{$name} for modules and themes/contrib/{$name} for themes, inside the web directory. The vendor directory sits beside web, not inside it.

Cite this definition

"Composer." DXPR Drupal glossary, https://dxpr.com/hc/documentation/learn-drupal/drupal-glossary/composer. Last updated October 26, 2026.

Related terms

All Drupal terms from A to Z