Setting up PHPStorm for Drupal

by Gisle Hannemyr

Mumble

Table of contents

Drupal project discussed in this chapter: Devel.

Introduction

[TBA]

Could not connect to a Docker provider. Please start or install a Docker provider. For install help go to: https://ddev.readthedocs.io/en/latest/users/install/

Install DDEV on Windows

To install DDEV on Windows:

First, install WSL2 with an Ubuntu distro:

PS C:\ wsl --install

Then reboot.

Verify that you have an Ubuntu distro set as default. In PowerShell:
PS C:\ wsl.exe -l -v
  NAME      STATE           VERSION
* Ubuntu    Running         2

You can also verify this in the Ubuntu CLI:

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04.2 LTS
Release:        22.04
Codename:       jammy

To install Docker and DDEV, in an administrative PowerShell run a PowerShell script by executing the following two command lines:

PS C:\ Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072;
PS C:\ iex ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/ddev/ddev/master/scripts/install_ddev_wsl2_docker_inside.ps1'))

The second line downloads and exedutes a PowerShell script that will setup the environment for Docker and download and install DDEV. When running this, you're asked to trust a certificate. Answer "Yes".

I got a couple of warnings:

WARNING: It's very likely you will need to close and reopen your shell before you can use choco.

RefreshEnv.cmd does not work when run from this process. If you're in PowerShell, please 'Import-Module $env:ChocolateyInstall\helpers\chocolateyProfile.psm1' and try again.

I did reopen PowerShell, and then ran the big script again.

To start an Upunti shell do:

PS C:\ wsl

Sources (ddev.readthedocs.io):

Install Drupal using DDEV

There is no need to install PHP or Composer under WSL2, they come as part of the DDEV environment.

DO: Local Development Guide.

The instructions below assumes that Drupal is installed in a siteroot named "drupal01":

$ mkdir drupal01
$ cd drupal01
$ ddev config --project-type drupal10 --create-docroot --docroot web

This will create a new DDEV project configured to host a Drupal 10 application. DDEV will store the generated configuration in a new .ddev subdirectory. Project name will be the same as the parent folder (drupal01).

Next, start the DDEV container:

$ ddev start

You now have a web server and database server configured and running. Configuring DDEV first allows us to run Composer from within DDEV instead of installing it locally.

Now create a new Drupal application with Composer:

$ ddev composer create drupal/recommended-project -y

You now have a web server and database server configured and running.

First, install the latest version of Drush:

$ ddev composer require drush/drush

Next, you must install Drupal using Drush, which populates your new database. You can specify the password for user #1 (username "admin") on the command line:

$ ddev drush si --account-pass=MyPassword -y

To generate a description of the new site, use:

$ ddev describe
+--------------------------------------------------------------------------------------------+
| Project: drupal01 ~/drupal01 https://drupal01.ddev.site                                    |
| Docker platform: wsl2-docker-ce                                                            |
| Router: traefik                                                                            |
+--------------------------------------------------------------------------------------------|
| SERVICE  | STAT | URL/PORT                                            | INFO               |
+----------+------+-----------------------------------------------------+--------------------|
| web      | OK   | https://drupal01.ddev.site                          | drupal10 PHP8.1    |
|          |      | InDocker: web:80,8025,443                           | nginx-fpm          |
|          |      | Host: 127.0.0.1:32775,32776                         | docroot:'web'      |
|          |      |                                                     | Perf mode: none    |
|          |      |                                                     | NodeJS:18          |
+----------+------+-----------------------------------------------------+--------------------|
| db       | OK   | InDocker: db:3306                                   | mariadb:10.4       |
|          |      | Host: 127.0.0.1:32774                               | User/Pass: 'db/db' |
|          |      |                                                     | or 'root/root'     |
+----------+------+-----------------------------------------------------+--------------------|
| Mailpit  |      | Mailpit: https://drupal01.ddev.site:8026            |                    |
|          |      | `ddev launch -m`                                    |                    |
+----------+------+-----------------------------------------------------+--------------------|
| All URLs |      | https://drupal01.ddev.site,                         |                    |
|          |      | https://127.0.0.1:32775, http://drupal01.ddev.site, |                    |
|          |      | http://127.0.0.1:32776                              |                    |
+--------------------------------------------------------------------------------------------+

Drupal is now installed, and you can visit it by typing the last URL given (i.e. "http://127.0.0.1:32776") into the address par of your browser.

Download and install Composer

windows phpstorm cannot connect is the docker daemon running

In the Settings dialog (Ctrl+Alt+S), navigate to Languages & frameworks » PHP » Composer.

JetBrains: Composer dependency manager

[TBA]

Final word

[TBA]


Last update: 2021-08-11 [gh].