3
3

More than 1 year has passed since last update.

【Drupal9】Docker × DDEVでDrupalローカル開発環境構築

Last updated at Posted at 2022-12-31

0. はじめに

『Drupal 9 Web開発ことはじめ』記載の環境構築がうまくいかなかったのでメモ。

0-1. 全体の流れ

1.DDEV
2.Drupal
3.git
4.appendix
Reference

0-2. 前提条件

  • Dockerインストール済み
  • Homebrewインストール済み

0-3.開発環境

key value
Drupal 9
PHP 8.1
Docker 20.10.21
Homebrew 3.4.10
OS macOS Ventura 13.1

1. DDEV

1-1. installation

local
$ brew install drud/ddev/ddev
$ brew upgrade ddev

1-2. error

local
$ brew install drug/ddev/ddev
Error: An exception occurred within a child process:
  CompilerSelectionError: drud/ddev/ddev cannot be built with any available compilers.
Install GNU's GCC:
  brew install gcc
  • gccをインストールしろと言われる。
local
$ brew install gcc
Error: gcc: the bottle needs the Apple Command Line Tools to be installed.
  You can install them, if desired, with:
    xcode-select --install

If you're feeling brave, you can try to install from source with:
  brew install --build-from-source gcc
  • xcode-selectが必要らしい。
local
$ xcode-select --install
xcode-select: note: install requested for command line developer tools
$ brew install drud/ddev/ddev
$ ddev
Create and maintain a local web development environment.
Docs: https://ddev.readthedocs.io
Support: https://ddev.readthedocs.io/en/stable/users/support

Usage:
  ddev [command]

Available Commands:
=== 略 ===

2. Drupal

2-1. installation

local
$ mkdir my-drupal9-site
$ cd my-drupal9-site
$ ddev config --project-type=drupal10 --docroot=web --create-docroot
$ ddev start
$ ddev composer create drupal/recommended-project
$ ddev composer require drush/drush
$ ddev drush site:install --account-name=admin --account-pass=admin -y
$ ddev drush uli
$ ddev launch

53e100a6-1fc8-46b1-a924-ff3cdd75b750.png

17db5572-eda0-42ec-a268-be077883208e.png

2-2. lang

1888e0de-3bb7-4c04-b928-07e19a611a6e.png

cfd5438c-58e8-43bf-8e89-aef15c8dfa9c.png

db28f571-4338-434d-bff3-03784029c3dd.png

491b9c5e-7615-4956-bd3c-b37e4e6d524c.png

de1c308d-329f-4634-a03f-d0a384dabcd1.png

378f6e2f-b97a-49a0-a644-3c87953f79f8.png

4e252e7b-2925-48c7-ac57-089f2d10da86.png

a8e34eb3-6c33-4cdc-b883-481543be8f08.png

2-3. locale

95557428-d6b3-4eb1-929e-b5ee774dce36.png

7e5033ea-159c-49be-951a-cc343804734d.png

3. git

3-1. .gitignore

  • サンプルはdrupal8ですが、9系のサンプルを見つけたら更新します。
local
$ cd my-drupal9-site
$ touch .gitignore
.gitignore
# Ignore directories generated by Composer
/drush/contrib/
/vendor/
/web/core/
/web/modules/contrib/
/web/themes/contrib/
/web/profiles/contrib/
/web/libraries/

# Ignore all site specific data
/web/sites/*
!/web/sites/default/
!/web/sites/example.sites.php

# Ignore IDE files
/.idea/
/.vscode/
*.iml
*.code-workspace

# Ignore all log files
*.log

# Ignore node modules
node_modules

# Ignore some css related stuff
*.css.map
*.css.map.map

# Ignore default text files
/CHANGELOG.txt
/COPYRIGHT.txt
/INSTALL*.txt
/LICENSE.txt
/MAINTAINERS.txt
/UPGRADE.txt
/README.txt
sites/README.txt
sites/all/modules/README.txt
sites/all/themes/README.txt

4. appendix

  • Drupal9は、PHP8.1以上がインストールされていないとエラーが出る。

local
$ ddev composer require drush/drush
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - drupal/core 10.0.0 requires php >=8.1.0 -> your php version (8.0.26) does not satisfy that requirement.
    - drupal/core-recommended 10.0.0 requires drupal/core 10.0.0 -> satisfiable by drupal/core[10.0.0].
    - drupal/core-recommended is locked to version 10.0.0 and an update of this package was not requested.

You can also try re-running composer require with an explicit version constraint, e.g. "composer require drush/drush:*" to figure out if any version is installable, or "composer require drush/drush:^2.1" if you know which you need.

Installation failed, reverting ./composer.json and ./composer.lock to their original content.
composer [require drush/drush] failed, composer command failed: exit status 2. stderr=
.ddev/config.yml
- php_version: "8.0"
+ php_version: "8.1"

Reference

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3