DDev

DDEV is an excellent framework for standardizing local development environments for Drupal projects.

Quickstart

# Start all containers.
ddev start

# List db snapshots.
ddev snapshot --list

# Create a db snapshot.
ddev snapshot

# Restore a db snapshot
ddev snapshot restore

Install DDEV

# Update brew.
brew update

# Install ddev.
brew install drud/ddev/ddev

# Configure locally-trusted dev certificates (will require sudo pass twice).
mkcert -install

# Configure nfs.
curl -O https://raw.githubusercontent.com/drud/ddev/master/scripts/macos_ddev_nfs_setup.sh && chmod +x macos_ddev_nfs_setup.sh && ./macos_ddev_nfs_setup.sh

# Remove above script after installation.
rm macos_ddev_nfs_setup.sh

To upgrade DDEV:

brew upgrade ddev

New Project

Steps to create a new Drupal 9 project with DDEV:

# Create a new project directory.
mkdir drupal9 && cd drupal9

# Create ddev config.
ddev config --project-type=drupal9 --docroot=web --create-docroot --project-name drupal9

# Start containers.
ddev start

# Create new Drupal project.
ddev composer create "drupal/recommended-project" --no-install

# Add dependencies.
ddev composer require drush/drush --no-install
ddev composer require 'drupal/admin_toolbar:^3.3' --no-install

# Install dependencies.
ddev composer install

# Install Drupal.
ddev drush site:install -y

# Enable modules.
ddev drush en admin_toolbar admin_toolbar_tools

# Get admin login.
ddev drush uli

# Or launch as anon.
ddev launch

Existing Project (D9)

Enter the project's root directory and run the following steps:

ddev config --project-type=drupal9 --docroot=web

# Edit .ddev/config.yml to change any of the default values (i.e, ) mysql, apache, etc.

# Install dependencies.
ddev composer install

# Add a new file (settings.development.php) to add to ddev settings.
# It should at least have the right config split.
# This is different from settings.local.php, which is ignored in git
# so it can be added to any environment.
# settings.development.php is only added for ddev environment.
# Yes, we could remove settings.ddev.php from the ignore list and commit it,
# but then we would always have to remember that in case something changes upstream.
cat <<'EOF' > web/sites/default/settings.development.php
<?php

$config['config_split.config_split.local']['status'] = TRUE;
EOF

# Include the custom settings file in main settings file.
# NOTE: it needs to be manually moved above the settings.local.php inclusion.
# Also, notice the single quote around first EOF,
# which is to escape everything (including the dollar sign).
cat <<'EOF' >> web/sites/default/settings.php

// Include additional custom settings for ddev environment.
if (getenv('IS_DDEV_PROJECT') == 'true') {
  include $app_root . '/' . $site_path . '/settings.development.php';
}
EOF

# Verify configuration.
ddev drush sql-connect

# Import db.
ddev import-db --src=~/archives/drupal9/db.sql

# Import files.
ddev import-files --src=~/archives/drupal9/files.tar.gz

# Run updatedb and import configuration.
ddev drush deploy

# Launch application in default browser.
ddev launch

Existing Project (D8)

An existing Drupal 8 project might require a little more customization to setup. We need to ensure PHP, MySQL, and composer versions match the project's requirements (for instance, it might require PHP 7.3, MySQL 8.0, and Composer 1. The --project-type should also be drupal8).

# Clone the repo in a directory called drupal8 (can be named anything).
git clone <clone-url> drupal8 && cd drupal8

# Configure ddev.
ddev config --project-type=drupal8 --docroot=web --project-name drupal8

# Install dependencies.
ddev composer install

# Add a new file (settings.development.php) to add to ddev settings.
# It should at least have the right config split.
# This is different from settings.local.php, which is ignored in git
# so it can be added to any environment.
# settings.development.php is only added for ddev environment.
# Yes, we could remove settings.ddev.php from the ignore list and commit it,
# but then we would always have to remember that in case something changes upstream.
cat <<'EOF' > web/sites/default/settings.development.php
<?php

$config['config_split.config_split.local']['status'] = TRUE;
EOF

# Include the custom settings file in main settings file.
# NOTE: it needs to be manually moved above the settings.local.php inclusion.
# Also, notice the single quote around first EOF,
# which is to escape everything (including the dollar sign).
cat <<'EOF' >> web/sites/default/settings.php

// Include additional custom settings for ddev environment.
if (getenv('IS_DDEV_PROJECT') == 'true') {
  include $app_root . '/' . $site_path . '/settings.development.php';
}
EOF

# Some projects might require a .env file for some other purpose
# (to perform hosting platform specific settings, i.e., PANTHEON).
touch .env

# Verify configuration.
ddev drush sql-connect

# Import db.
ddev import-db --src=~/archives/drupal8/db.sql

# Import files.
ddev import-files --src=~/archives/drupal8/files.tar.gz

# Or launch as anon.
ddev launch

Resources