HOWTO.development_tools - raynaldmo/HOWTO GitHub Wiki

Docker

Docker Courses

DDEV

Docker Installation

DDEV Installation

  • Homebrew - macOS/Linux
  • For macOS (both amd64 and arm64) and Linux users, we recommend installing and upgrading via Homebrew (macOS)
    or Homebrew on Linux (Linux)
brew install drud/ddev/ddev
  • If you would like more frequent "edge" releases then use brew install drud/ddev-edge/ddev instead.
  • As a one-time initialization, run mkcert -install
  • Later, to upgrade to a newer version of DDEV-Local, run:
ddev poweroff && brew upgrade drud/ddev/ddev
  • Update to a specific version
# If previous version was installed by Homebrew
brew unlink ddev

# Install specific version
curl -fsSL https://ddev.com/install.sh | bash -s v1.24.1

Tips

  • Update / Change database
ddev debug migrate-database mariadb:10.4

PhpStorm

PhpStorm Drupal & DDEV Setup

Debugging Notes

  • In settings.local.php, check that Internal Page Cache and Dynamic Page Cache is disabled, otherwise
    breakpoints won't be hit
...
$settings['cache']['bins']['page'] = 'cache.backend.null';
$settings['cache']['bins']['dynamic_page_cache'] = 'cache.backend.null';
...
  • Enable Xdebug for the project
<top-level-project-directory>$ ddev xdebug on
  • Turn off Xdebug when not debugging
<top-level-project-directory>$ ddev xdebug status; ddev xdebug off

VSCode Drupal Setup

Coding Standards

ddev composer require --dev dealerdirect/phpcodesniffer-composer-installer
ddev composer require --dev drupal/coder
  • Install phpcs locally into project
ddev composer require --dev squizlabs/php_codesniffer
# ssh into project web container
<top-level-project-directory>$ ddev ssh

# Check installed coding standards
/var/www/html$ phpcs -i
The installed coding standards are MySource, PEAR, PSR1, PSR2, PSR12, Squiz, Zend, Drupal, DrupalPractice, VariableAnalysis and SlevomatCodingStandard

# Check files in web/modules/custom for Drupal coding standards
/var/www/html$ phpcs -p --colors --standard=Drupal,DrupalPractice --extensions=php,module,install web/modules/custom/

# Fix files in web/modules/custom to comply with Drupal coding standards
/var/www/html$ phpcbf -p --colors --standard=Drupal,DrupalPractice --extensions=php,module,install web/modules/custom/

Debugging

  • Enable Xdebug for the project
<top-level-project-directory>$ ddev xdebug on
  • Turn off Xdebug when not debugging
<top-level-project-directory>$ ddev xdebug status; ddev xdebug off
  • From VSCode Click on the Run and Debug Icon (on left panel)
  • Click the "Listen for XDebug" dropdown menu and then click on “Add configuration”
  • This will open up the launch.json file which we are going to edit
  • Remove the existing content in the file and paste in the following code.
{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Listen for XDebug",
      "type": "php",
      "request": "launch",
      "port": 9003,
      "pathMappings": {
        "/var/www/html": "${workspaceRoot}"
      },
      "xdebugSettings": {
        "show_hidden": 1
      }
    }
  ]
}
  • Configure .ddev/docker-compose.xdebug.yaml as below - Not sure this is needed ?
version: "3.6"
services:
    web:
        extra_hosts:
            - "host.docker.internal:192.168.65.2"
  • Set breakpoint at codepoint
  • Click "Listen for XDebug" green arrow at top VSCode bar - bottom VSCode bar should turn from blue to orange
  • Also See PHP Step Debugging

VSCode WordPress Setup

TBD