Install Drupal 8 using Composer

Submitted by roo on Mon, 11/07/2016 - 09:19

The simplest way to install Drupal 8 initially is, at first glance, to simply download the tarball and decompress it.

In the long-run though, it's better to use Composer package-manager at the outset, as it's almost certain you will need it in the future anyway. It's pretty simple to do once you know the steps.

Firstly you need to install the composer.

If you are on shared hosting, this may be an issue. In this case, the technique is to install composer on your local machine, and then when you have created the installation directory as described below, copy the whole directory structure up to your host (preferably using sftp)

This article assumes you are hosting on Linux (or your local machine is Linux if using shared hosting). The process will be very similar for MacOSX. If you are using Window's there will be differences that are clear from the 'composer' documentation etc..

Use the instructions here to install it.

Then do:
mv composer.phar /usr/local/bin/composer

Composer can then be run from any directory.

Drupal has it's own repo for composer.

There is information about the process of installing Drupal using Composer here:

The drupal-composer/drupal-project still provides the best 'scaffold' at the time of writing.

To install a Drupal project, create a directory for the website (eg /var/www/vhost/ and cd into that directory.

Then run:

composer create-project drupal-composer/drupal-project:8.x-dev drupal-8.x --stability dev --no-interaction

this will create a drupal-8.x directory, under which will be the installation. Drupal in installed in drupal-8.x/web

Next create a link to there:

ln -s drupal-8.x/web htdocs

htdocs is your root directory for your webserver configuration.

If want to add a single module (or theme), then in that drupal-8.x directory, run :
composer require "drupal/module-name"

This will sometimes install the dev version when you want the alpha, or beta. Edit composer.json and alter the version. Using something like "drupal/coffee" : "1.*@dev" will install the dev version until there's a stable and then install the stable. 
Run composer update  to update from the dev versions. (Check

To update all (core, modules, themes) then run composer update. 
If you are on shared hosting, do this on your local machine, then copy up again. If you have already made customisations to themes (or anything else), then be careful not to over-write those changes.