Composer is a tool for managing PHP dependencies for your website or application.
To install Composer for use with your website, complete the following steps:
- Download Composer from its download page.
- To allow you to install Composer, depending on your operating system, download and install the appropriate package manager using the instructions on its download page:
- Open a command prompt window.
- Install Composer using the appropriate command, based on your operating system:
- Mac/Unix -
brew install composer
- Windows -
scoop install composer
- Mac/Unix -
- Composer dependencies will be installed to a
vendordirectory in your project. Ideally, these dependencies should not be placed under version control except for deployment to Acquia Cloud.
- Update your
.gitignorefile to ignore changes to your
Using Composer with Acquia Cloud
Because Composer is not installed on Acquia Cloud, we recommend 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.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)
It is possible, but not recommended, to use a Composer-based workflow with only a single repository. Using a single repository creates a brittle development workflow, which can make it difficult to maintain code consistency. For instance, with a single repository, the versions of dependencies in
composer.json and the versions of dependencies actually committed to the repository must be kept in sync, which introduces a high risk of human error.
If you are unable to use the Acquia Cloud pipelines feature, you can use Composer based on the following methods:
- Using Acquia BLT's
deploycommands, as described in Acquia BLT's Deployment workflow
- Installing Composer through Live Development (not recommended)
It is also possible to install Composer in Acquia Cloud, but to do so you will need to both enable Live Development and follow normal Git workflow for checking out the code (including adding the changed flags, committing the changes, and pushing to origin).
After installing Composer, using Composer on Acquia Cloud requires Live Development mode to be enabled. For more information about working with Live Development, see Live Development workflow.
By default the
.gitignorefile ignores the
Vendordirectory, which makes sense if you are using Composer on Acquia Cloud directly.
Using Composer with Drupal
The installation methods and available resources for Composer depend on your installed version of Drupal.
- Drupal 8.0.x
If you are using Drupal versions less than version 8.1, you can install the Composer Manager module to help you manage Composer's
composer.jsonfiles. We recommend that you follow the recommended settings on the Composer Manager for Drupal 6 and Drupal 7 page on Drupal.org, and then apply the recommended settings from the Production Environments section of the same page.
For more information about this process, see the Using Composer Manager to get off the Island Now blog post from Acquia.com's Developer website.
- Drupal 8.1 and greater
Starting with Drupal 8.1, Drupal core directly uses Composer to manage dependencies, which can include Drupal modules. Instead of using the Composer Manager module, the recommended workflow for a module with Composer dependencies is to require the module itself through Composer. For more information, see the following Drupal.org resources:
- Drupal 8.4 and greater
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.