Using Composer with Drupal 8 sites

Composer is a tool for managing PHP dependencies for your website or application. It allows you to declare the libraries your project depends on, and it will install and update them for you.

For full instructions about downloading and installing Composer for your operating system, see the Composer’s Getting Started guide.

Using Composer with Acquia Cloud

Because Composer is not installed on Acquia Cloud, Acquia recommends that you install Composer locally and use it with your local copy to perform updates and manage dependencies. You can then deploy your build artifact to your Acquia Cloud environments using the Acquia Cloud pipelines feature.

To follow best practices with Composer, you should maintain a source code (source) repository for your project that is separate from your Acquia Cloud (build) repository. Your source repository should contain only the minimum amount of code required to build your project, such as a composer.json file, composer.lock file, and any custom modules or settings. The source repository should not contain copies of your Composer dependencies. Your build repository (hosted on Acquia Cloud) should contain static snapshots, called build artifacts, of your entire codebase (including Composer dependencies) that are ready for deployment to Acquia Cloud.

To move code between your source and build repositories, you can use one of the following methods:

  • Copy the necessary files locally
  • Use a continuous integration service, such as the Acquia Cloud pipelines feature
  • Use a tool that automates this process, such as Acquia BLT

You can use a Composer-based workflow with only a single repository (not recommended). This creates a brittle development workflow, which can make it difficult to maintain code consistency. For instance, with a single repository, you must keep the versions of dependencies in composer.json and the versions of dependencies you commit to the repository in sync, which introduces a high risk of human error.

If you can’t use the Acquia Cloud pipelines feature, you can use Composer based on the following methods:

  • Using Acquia BLT deploy commands, as described in the Acquia BLT Deployment workflow
  • Installing Composer through Live Development (not recommended)
    You can install Composer in Acquia Cloud by enabling Live Development and following the normal Git workflow for checking out code (including adding changed flags, committing changes, and pushing to origin). After you install Composer, you must enable Live Development mode to begin using Composer on Acquia Cloud. By default the .gitignore file ignores the Vendor directory, which makes sense if you use Composer on Acquia Cloud directly.

Using Composer with Drupal

In Drupal versions 8.1 and greater, Drupal core uses Composer to manage dependencies, which can include Drupal modules. For more information, see the following Drupal.org resources:

Starting with Drupal 8.4, a minimum version of Drush 8.1.12 is required if installed globally, and Drush 8.1.15 if required at the project level using Composer.

Migrating into a Composer-managed build

If you migrate an existing Drupal 8 website into a Composer-managed build, you must build a composer.json file that includes all of the packages that your existing website requires. For more information about the migration process, see the Composer: Migrate an existing D8 site into a Composer-managed build documentation page.

Contact supportStill need assistance? Contact Acquia Support

Acquia: Think Ahead

53 State Street, 10th Floor
Boston, MA 02109
United States
Phone: 888-922-7842

Map: Google Maps
View other locations