Skip to Main Menu

Drupal 8 Composer Drush

Table of Contents

My notes for installing Drupal 8 on localhost (MAMP/Docker/VM/other) with Composer while using the power of Drush.

By no means is this a definitive guide, simply a working document to outline steps in process.

You’ll get the majority of the goods here:

Installing Drupal w/ Composer

Listed here:

https://www.drupal.org/docs/develop/using-composer/using-composer-to-manage-drupal-site-dependencies#creating-new

Drupal Composer config generator (drupal-init)

We’re going to try Option C on above link

hussainweb/drupal-composer-init

The drupal-init command creates a composer.json file usable for Drupal projects in the current directory.

Here is what it looks like:

Composer.json file for Drupal 8

Commands go something like this:

composer global require hussainweb/drupal-composer-init

# navigate to new folder, create composer.json file
composer drupal-init

Working with an existing D8 Project?

Check this: https://www.drupal.org/project/composer_generate

Installation - Let’s go!

From what I see, 2 options for installation

  1. Via browser
  2. Command line

We’re going with for the Command line installation with Drush

Drush

It is recommended that Drupal 8 sites be built using Composer, with Drush listed as a dependency. http://docs.drush.org/en/master/install/

With Drush, you can:

  • Download and install Drupal
  • Clear cache
  • Update Drupal & contrib modules
  • Add users and permissions
  • Backup & restore
  • Run Drupal w/ web server

Since we’re using ‘hussainweb/drupal-composer-init’, we can proceed to install D8

Create database

mysql -u root -p

create database d8-something;

exit;

Let’s install it

drush site-install standard --db-url=mysql://[db_user]:[db_pass]@[ip-address]/[db_name]

Pay attention here - admin password is given here!

It’s Alive

Navigate to your local website and you will see Drupal 8 installed.

Enable modules

Header over to Extend and check to see what modules are enabled.

Since we stated that we also wanted a few modules within our composer.json, you will see that they’re not enabled.

Composer.json file for Drupal 8

drush en [module-name]

drush en pathauto

Should any one of them have dependancies, they you get prompted as well.

Nifty!

Themes

View your themes

drush pm:list --type=theme

Clear Cache

drush cr

Download & enable module

https://www.drupal.org/docs/user_guide/en/install-composer.html

Theme

Download with composer

composer require drupal/bootstrap

Enable with Drush fails - have to enable via D8 admin

drush en bootstrap

# get error

[error]  Unable to install modules Bootstrap due to missing modules Bootstrap.

Recap

Here we have:

  • Generated composer.json file using hussainweb/drupal-composer-init
  • Set up extensions
  • Downloaded Drupal 8 in to working folder with composer
  • Connected to database and installed with Drush
  • Enabled module with Drush

More to follow!