Setup Drupal locally with DDEV

1.0
Drupal 10
DDEV
DOCKER

This article aims to assist BBD colleagues in the installation and familiarization of DDEV for their local development. The focus here is on providing step-by-step instructions for setting up a Drupal project locally using DDEV. 

Why docker?

Docker has gained significant popularity due to its advantages, including portability, consistency, and scalability for deploying applications across diverse environments. At Big Blue Door, we advocate the use of Docker to ensure the following benefits: 

  1. Consistent Development Environments: Docker ensures that all developers share the same setup on their localhost. 
  2. Efficient Project Setup: With Docker, setting up a new project becomes swift and hassle-free, eliminating the need to install each web application individually. 
  3. Minimized Deployment Issues: Docker helps in reducing side effects or unexpected errors when deploying to development, staging, and live environments. 

DDEV or Lando? 

When it comes to setting up a Drupal project, two prominent tools, DDEV and Lando, stand out. The choice between them is subjective, and individuals can select the Docker-based application that best suits their preferences. Personally, I favour DDEV for its association with the NOT-FOR-profit organization "The DDEV Foundation" while Lando is affiliated with the FOR-profit organization "Lando System, Inc."

Instructions

  1. Go to the DDEV site and follow their instructions to install DDEV: https://ddev.com/get-started/
  2. Go to BBD Git repos, and clone the Drupal project that we need to set it up locally:

    git clone project_url
  3. Go to the project folder, then start DDEV:

    ddev start
    ddev config –-auto
    ddev composer update
    ddev config –-auto // at this point, DDEV will recognise that this is a Drupal project.
    ddev restart
  4. Request a copy of the DB, then import it

    ddev import-db < db.sql
  5. Check .ddev/config.yml and make sure all the configurations are correct:

    type: drupal9
    docroot: web
    php_version: "8.1"
  6. Insert at the end of this file web/sites/default/settings.php for local development:

    $settings['config_sync_directory'] = '../config/sync';
    $config['system.logging']['error_level'] = 'verbose'; // hide|some|all|verbose
    $config['system.performance']['cache']['page']['max_age'] = 0;
    $config['system.performance']['css']['preprocess'] = FALSE;
    $config['system.performance']['js']['preprocess'] = FALSE;
  7. Duplicate web/sites/default/default.services.yml to web/sites/default/services.yml  and enable twig debug mode:

    debug: true
    auto_reload: null
    cache: false

    To set up other CMS, please check here

Other extensions

  1. Install phpmyadmin

    ddev get ddev/ddev-phpmyadmin && ddev restart
  2. Install Solr: https://github.com/ddev/ddev-drupal9-solr

    ddev get ddev/ddev-drupal9-solr && ddev restart
  3. Other addition servers: https://ddev.readthedocs.io/en/latest/users/extend/additional-services/

Useful tips

  1. Enable xdebug

    ddev xdebug
  2. Enable xhprof Profiling

    ddev xhprof
  3. Save/Restore DB

    ddev snapshot --name=db_name
    ddev restore

References