Add Composer to an existing site

Simplified in Drupal 8.8.0

Please note: If you started your project using Drupal version 8.8.0 or later, your site already uses the correct file structure and is ready to be converted to Composer.

This page is a step by step guide to manually adding Composer support to an existing site that was previously installed without Composer. This howto is for you if you installed a Drupal site manually from a tarball or have used an abandoned Composer template like drupal/drupal.

Troubleshooting Composer

Troubleshooting Composer can be frustrating. Composer is doing many complex things for you, and there's a degree of understanding required to effectively troubleshoot issues that arise.

This page is intended to provide troubleshooting techniques and to enumerate common problems. It is not intended to be exhaustive. If you're having a problem not described here, performing an internet search for your specific error message may be more helpful.

Managing dependencies for a custom project

You can use Composer to manage dependencies for your custom modules. To do this, your Drupal site's composer.json (located in the repo root) must have a way to read your custom project's composer.json file. If your custom project is not hosted on Packagist or Drupal.org, you may use a Composer path repository to accomplish this.

Find the repositories section of your root composer.json file, and modify it to include your custom module or modules as path repositories:

Using packages.drupal.org

Background

By default, Composer uses Packagist.org to discover packages. Packagist.org is a repository of metadata about PHP and PHP-related projects. 

Drupal projects are not listed on Packagist. Instead, Drupal.org provides its own repository of composer metadata for Drupal projects.

Subscribe with RSS Subscribe to RSS - Composer.json