A blog by Ian Wright - Front-end web developer
I have recently been working on a lot of Drupal 8 sites and a few modules have had Composer dependencies. When I first looked into how the dependencies worked I always seemed to hit a problem where I didn’t know how dependencies should be installed for Drupal. This is a brain dump of how I get Composer dependencies for Drupal modules working successfully.
Run the following command from terminal to create a Phar (PHP Archive) file called composer.phar
curl -sS https://getcomposer.org/installer | php
To make Composer globally accessible by simply typing composer. The file needs to be moved to /usr/local/bin/ and then an alias needs to be setup:
sudo mv composer.phar /usr/local/bin/ pico ~/.bash_profile
Inside ~/.bash_profile add the following line.
alias composer="php /usr/local/bin/composer.phar"
Relaunch terminal or run source ~/.bash_profile and you should be able to access Composer by typing composer.
Drupal needs to know the Composer endpoint, there are two versions, one for Drupal 7 & one for 8. From the Drupal root of your project the following command needs be executed. (Please note this is using the Drupal 8 endpoint)
composer config repositories.drupal composer https://packages.drupal.org/8
Once Composer knows about the endpoints the Composer packages can be install.
More information about Composer and the different versions can be found on drupal.org.