2.1 Reference

Notes from: Drupal 8 Day: Improve Your Drupal 8 Development Workflow Using Composer

2.2 Drupal template

Use the Drupal Composer template file Drupal Template

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

Although this command specifies 8.x-dev the composer.json file that generates the projects requires:

        "drupal/core": "~8.0",
        "drush/drush": "~8.0",
        "drupal/console": "~1.0"

So the lastest stable version is installed… That's odd… But let's carry on...

2.3 File Structure

You will find that vendor folder and web folder are separate. Serve the web folder...

2.4 Committing to Git

Always commit your composer.lock file.

Create you git repo of the new project:

git init

You will see the project contains a .gitignore file

You will see the vendor folder is excluded so we don't commit 3rd party libraries. Its a light-weight repo like it should be!!

2.5 Use Drupal Console to install the site

N.B. - No spaces, underscores, hyphen, or funny characters in the --db-name

drupal site:install standard --langcode="en" \
--db-type="mysql" --db-host="127.0.0.1" \
--db-name="databasename" --db-user="root" \
--db-pass="root-user-password" --db-port="3306" \
--site-name="Site Name" \
--site-mail="site@mail.com" \
--account-name="admin" \
--account-mail="admin@mail.com" \
--account-pass="admin" \
--no-interaction

2.6 Serve the site with Drupal Console

drupal server

No more setting up vhosts… This serves the site on port: 8088

Open up the site in an IDE with an integrated terminal and you can code and work with composer, drush and drupal console in one fluid process…

2.7 Secure sync files

Since we have this structure why not move the config/sync files outside the web directory. Maybe to ../config/sync

Once you move the files, tell D8 where to find them. There is no need for the hash in the path anymore since the files are outside the web root.

@ web/sites/default/settings.php

Change this

$config_directories['sync'] = 'sites/default/files/config_hjcQQyuNCfTiBHxPvw1vwT-GzZf3GqmBNv47CrlWtcl9CThwSxbscwABi6SQ39yeFKMpAc9hVA/sync';

To this:

$config_directories['sync'] = '../config/sync';

2.8 Git commit

Commit everything.