Study Guide: Installing a Drupal 9 Local Development Environment

Prerequisites

  1. Homebrew https://docs.brew.sh/Installation
  2. Git https://git-scm.com/
  3. Docker https://docs.docker.com/get-docker/
  4. ddev https://ddev.readthedocs.io/en/stable/

1. Install ddev

$ brew tap drud/ddev && brew install drud/ddev/ddev

Verify version

$ ddev version

2. Create Project Directory

Warning: Avoid project-names-with-hyphens! ddev doesn’t like them.

$ mkdir d9
$ cd d9

3. Create default Drupal 9 directory structure.

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

4. Build a Docker container for the project based on settings in .ddev dir.

$ ddev start

5. Install Drupal core, libraries, and resources, and create a default project.

$ ddev composer create "drupal/recommended-project"

6. Install drush.

$ ddev composer require "drush/drush"

7. Configure the Drupal 9 Project

Option 1: Launch interactive configuration, or…

ddev launch

Option 2: Use Drush.

$ ddev exec drush site:install --account-name=admin --account-pass=admin
$ ddev launch

8. Adjust and check file security

$ chmod 555 web/sites/default
$ chmod 444 web/sites/default/settings.php
$ ls -alhd web/sites/default web/sites/default/settings.php
# Output
$ dr-xr-xr-x 8 [ron] staff 256 Jul 21 12:56 web/sites/default
$ -r--r--r-- 1 [ron] staff 249 Jul 21 12:12 web/sites/default/settings.php

9. A few more useful ddev commands

ddev stop
ddev stop [project]
ddev list

10. Create .gitignore file.

# gitignore template for Drupal 8 projects
#
# earlier versions of Drupal are tracked in `community/PHP/`
#
# follows official upstream conventions:
# https://www.drupal.org/docs/develop/using-composer

# Ignore configuration files that may contain sensitive information
/web/sites/*/*settings*.php
/web/sites/*/*services*.yml

# Ignore paths that may contain user-generated content
/web/sites/*/files
/web/sites/*/public
/web/sites/*/private
/web/sites/*/files-public
/web/sites/*/files-private

# Ignore paths that may contain temporary files
/web/sites/*/translations
/web/sites/*/tmp
/web/sites/*/cache

# Ignore drupal core (if not versioning drupal sources)
/web/vendor
/web/core
/web/modules/README.txt
/web/profiles/README.txt
/web/sites/development.services.yml
/web/sites/example.settings.local.php
/web/sites/example.sites.php
/web/sites/README.txt
/web/themes/README.txt
/web/.csslintrc
/web/.editorconfig
/web/.eslintignore
/web/.eslintrc.json
/web/.gitattributes
/web/.htaccess
/web/.ht.router.php
/web/autoload.php
/web/composer.json
/web/composer.lock
/web/example.gitignore
/web/index.php
/web/INSTALL.txt
/web/LICENSE.txt
/web/README.txt
/web/robots.txt
/web/update.php
/web/web.config

# Ignore vendor dependencies and scripts
/vendor
/composer.phar
/composer
/robo.phar
/robo
/drush.phar
/drush
/drupal.phar
/drupal

# Ignore directories generated by Composer
/drush/contrib/
/vendor/
/web/core/
/web/modules/contrib/
/web/themes/contrib/
/web/profiles/contrib/
/web/libraries/

# Ignore SimpleTest multi-site environment
/web/sites/simpletest

# Ignore files generated by common IDEs
/.idea/
/.vscode/

# Ignore .env files as they are personal
/.env

11. Configure git

$ git init
$ git remote origin drupal
$ git remote add origin path/to/git/repo
$ git add .
$ git commit -m "Initial commit"
$ git status
$ git push

Sources

  1. https://www.digitalocean.com/community/tutorials/how-to-develop-a-drupal-9-website-on-your-local-machine-using-docker-and-ddev
  2. https://it.umn.edu/services-technologies/how-tos/drupal-9-set-local-environment
Source: //study/drupal/installing-drupal9-local-dev/