Cara menggunakan config debug phpstorm

In this part of the tutorial series on developing PHP on Docker we will set up our local development environment to be used by PhpStorm and Xdebug. We will also ensure that we can run PHPUnit tests from the command line as well as from PhpStorm and throw the tool

# File: .docker/images/php/base/Dockerfile

FROM base as local

RUN apk add --no-cache --update \
        php-xdebug~=${TARGET_PHP_VERSION} \
    # ensure that xdebug is not enabled by default
    && rm -f /etc/php8/conf.d/00_xdebug.ini
1 into the mix for debugging long-running processes.

All code samples are publicly available in my Docker PHP Tutorial repository on Github.
You find the branch for this tutorial at part-4-2-phpstorm-docker-xdebug-3-php-8-1-in-2022

All published parts of the Docker PHP Tutorial are collected under a dedicated page at Docker PHP Tutorial. The previous part was Docker from scratch for PHP 8.1 Applications in 2022 and the following one is Run Laravel 9 on Docker in 2022.

If you want to follow along, please subscribe to the RSS feed or to get automatic notifications when the next part comes out :)

Table of contents

Introduction

This article is mostly an update of Setting up PhpStorm with Xdebug for local development on Docker but will also cover the "remaining cases" of debugging php-fpm and php worker processes.

We will still rely on an always-running docker setup that we connect to via an SSH Configuration instead of using the as I feel it's closer to what we do in CI / production. However, we will not use SSH keys any longer but simply authenticate via password. This reduces complexity and removes any pesky warnings regarding "SSH keys being exposed in a repository".

Install Tools

Install composer

Composer is installed by pulling the official composer docker image and simply "copying" the composer executable over to the base php image. In addition, composer needs the extensions

# File: .docker/images/php/base/Dockerfile

FROM base as local

RUN apk add --no-cache --update \
        php-xdebug~=${TARGET_PHP_VERSION} \
    # ensure that xdebug is not enabled by default
    && rm -f /etc/php8/conf.d/00_xdebug.ini
2 and
# File: .docker/images/php/base/Dockerfile

FROM base as local

RUN apk add --no-cache --update \
        php-xdebug~=${TARGET_PHP_VERSION} \
    # ensure that xdebug is not enabled by default
    && rm -f /etc/php8/conf.d/00_xdebug.ini
3

# File: .docker/images/php/base/Dockerfile

ARG ALPINE_VERSION
ARG COMPOSER_VERSION
FROM composer:${COMPOSER_VERSION} as composer
FROM alpine:${ALPINE_VERSION} as base

# ...

RUN apk add --update --no-cache  \
        php-mbstring~=${TARGET_PHP_VERSION} \
        php-phar~=${TARGET_PHP_VERSION} \

# ...

COPY --from=composer /usr/bin/composer /usr/local/bin/composer

Because we want our build to be deterministic, we "pin" the composer version by adding a

# File: .docker/images/php/base/Dockerfile

FROM base as local

RUN apk add --no-cache --update \
        php-xdebug~=${TARGET_PHP_VERSION} \
    # ensure that xdebug is not enabled by default
    && rm -f /etc/php8/conf.d/00_xdebug.ini
4 variable to the
# File: .docker/images/php/base/Dockerfile

FROM base as local

RUN apk add --no-cache --update \
        php-xdebug~=${TARGET_PHP_VERSION} \
    # ensure that xdebug is not enabled by default
    && rm -f /etc/php8/conf.d/00_xdebug.ini
5 file

COMPOSER_VERSION=2.2.5

and using it in

# File: .docker/images/php/base/Dockerfile

FROM base as local

RUN apk add --no-cache --update \
        php-xdebug~=${TARGET_PHP_VERSION} \
    # ensure that xdebug is not enabled by default
    && rm -f /etc/php8/conf.d/00_xdebug.ini
6:

services:
  php-base:
    build:
      args:
        - COMPOSER_VERSION=${COMPOSER_VERSION?}

Install Xdebug

Install the extension via

# File: .docker/images/php/base/Dockerfile

FROM base as local

RUN apk add --no-cache --update \
        php-xdebug~=${TARGET_PHP_VERSION} \
    # ensure that xdebug is not enabled by default
    && rm -f /etc/php8/conf.d/00_xdebug.ini
7 (only for the
# File: .docker/images/php/base/Dockerfile

FROM base as local

RUN apk add --no-cache --update \
        php-xdebug~=${TARGET_PHP_VERSION} \
    # ensure that xdebug is not enabled by default
    && rm -f /etc/php8/conf.d/00_xdebug.ini
8 target):

# File: .docker/images/php/base/Dockerfile

FROM base as local

RUN apk add --no-cache --update \
        php-xdebug~=${TARGET_PHP_VERSION} \
    # ensure that xdebug is not enabled by default
    && rm -f /etc/php8/conf.d/00_xdebug.ini

We also don't want to enable

# File: .docker/images/php/base/Dockerfile

FROM base as local

RUN apk add --no-cache --update \
        php-xdebug~=${TARGET_PHP_VERSION} \
    # ensure that xdebug is not enabled by default
    && rm -f /etc/php8/conf.d/00_xdebug.ini
9 immediately but only when we need it (due to the decrease in performance when the extension is enabled), hence we remove the default config file and disable the extension in the application
# File: .docker/images/php/base/conf.d/zz-app-local.ini

; Note:
; Remove the comment ; to enable debugging
;zend_extension=xdebug
xdebug.client_host=host.docker.internal
xdebug.start_with_request=yes
xdebug.mode=debug
0 file

# File: .docker/images/php/base/conf.d/zz-app-local.ini

; Note:
; Remove the comment ; to enable debugging
;zend_extension=xdebug
xdebug.client_host=host.docker.internal
xdebug.start_with_request=yes
xdebug.mode=debug

See for an explanation of the

# File: .docker/images/php/base/conf.d/zz-app-local.ini

; Note:
; Remove the comment ; to enable debugging
;zend_extension=xdebug
xdebug.client_host=host.docker.internal
xdebug.start_with_request=yes
xdebug.mode=debug
1 setting (previously called
# File: .docker/images/php/base/conf.d/zz-app-local.ini

; Note:
; Remove the comment ; to enable debugging
;zend_extension=xdebug
xdebug.client_host=host.docker.internal
xdebug.start_with_request=yes
xdebug.mode=debug
2 in xdebug < 3). This will still work out of the box for Docker Desktop, but for Linux users we need to add the to all PHP containers (we can't add it to the php base image because this is a runtime setting):

services:
  service:
    extra_hosts:
      - host.docker.internal:host-gateway

Finally, we need to add the environment variable

# File: .docker/images/php/base/conf.d/zz-app-local.ini

; Note:
; Remove the comment ; to enable debugging
;zend_extension=xdebug
xdebug.client_host=host.docker.internal
xdebug.start_with_request=yes
xdebug.mode=debug
4 to all PHP containers. The variable is defined as
# File: .docker/images/php/base/conf.d/zz-app-local.ini

; Note:
; Remove the comment ; to enable debugging
;zend_extension=xdebug
xdebug.client_host=host.docker.internal
xdebug.start_with_request=yes
xdebug.mode=debug
5, where "dofroscra" is the name of the server that we will configure later for debugging. Because we need the same value in multiple places, the variable is configured in
# File: .docker/images/php/base/Dockerfile

FROM base as local

RUN apk add --no-cache --update \
        php-xdebug~=${TARGET_PHP_VERSION} \
    # ensure that xdebug is not enabled by default
    && rm -f /etc/php8/conf.d/00_xdebug.ini
5:

PHP_IDE_CONFIG=serverName=dofroscra

And then added in

# File: .docker/images/php/base/conf.d/zz-app-local.ini

; Note:
; Remove the comment ; to enable debugging
;zend_extension=xdebug
xdebug.client_host=host.docker.internal
xdebug.start_with_request=yes
xdebug.mode=debug
7

services:
  php-fpm:
    environment:
      - PHP_IDE_CONFIG=${PHP_IDE_CONFIG?}

  php-worker:
    environment:
      - PHP_IDE_CONFIG=${PHP_IDE_CONFIG?}

  application:
    environment:
      - PHP_IDE_CONFIG=${PHP_IDE_CONFIG?}

Install PHPUnit

PHPUnit will be installed via

# File: .docker/images/php/base/conf.d/zz-app-local.ini

; Note:
; Remove the comment ; to enable debugging
;zend_extension=xdebug
xdebug.client_host=host.docker.internal
xdebug.start_with_request=yes
xdebug.mode=debug
8 but will not be "baked into the image" for local development. Thus, we must run
# File: .docker/images/php/base/conf.d/zz-app-local.ini

; Note:
; Remove the comment ; to enable debugging
;zend_extension=xdebug
xdebug.client_host=host.docker.internal
xdebug.start_with_request=yes
xdebug.mode=debug
9 in the container. To make this more convenient a make target for running arbitrary composer commands is added in
services:
  service:
    extra_hosts:
      - host.docker.internal:host-gateway
0:

.PHONY: composer
composer: ## Run composer commands. Specify the command e.g. via ARGS="install"
    $(EXECUTE_IN_APPLICATION_CONTAINER) composer $(ARGS);

This allows me to run

services:
  service:
    extra_hosts:
      - host.docker.internal:host-gateway
1 from the host system to execute
services:
  service:
    extra_hosts:
      - host.docker.internal:host-gateway
2 in the container. In consequence,
# File: .docker/images/php/base/conf.d/zz-app-local.ini

; Note:
; Remove the comment ; to enable debugging
;zend_extension=xdebug
xdebug.client_host=host.docker.internal
xdebug.start_with_request=yes
xdebug.mode=debug
8 will use the PHP version and extensions of the
services:
  service:
    extra_hosts:
      - host.docker.internal:host-gateway
4 container to install the dependencies, yet I will still see the installed files locally because the codebase is configured as a volume for the container.

Before installing phpunit, we must add the required extensions

services:
  service:
    extra_hosts:
      - host.docker.internal:host-gateway
5 and
services:
  service:
    extra_hosts:
      - host.docker.internal:host-gateway
6 to the container

# File: .docker/images/php/base/Dockerfile

# ...

RUN apk add --update --no-cache  \
        php-dom~=${TARGET_PHP_VERSION} \
        php-xml~=${TARGET_PHP_VERSION} \

as well as rebuild and restart the docker setup via

COMPOSER_VERSION=2.2.5
0

Now we can add phpunit via

COMPOSER_VERSION=2.2.5
1

which will create a

services:
  service:
    extra_hosts:
      - host.docker.internal:host-gateway
7 file and setup up the
services:
  service:
    extra_hosts:
      - host.docker.internal:host-gateway
8 directory:

COMPOSER_VERSION=2.2.5
2

CAUTION: If you run into the following permission error at this step, you are likely using Linux and haven't set the

services:
  service:
    extra_hosts:
      - host.docker.internal:host-gateway
9 and
PHP_IDE_CONFIG=serverName=dofroscra
0 variables as described in the previous article under .

COMPOSER_VERSION=2.2.5
3

I have also added

  • a minimal
    PHP_IDE_CONFIG=serverName=dofroscra
    
    1 config file
  • a test case at
    PHP_IDE_CONFIG=serverName=dofroscra
    
    2
  • and a new Makefile for "anything related to qa" at
    PHP_IDE_CONFIG=serverName=dofroscra
    
    3:
COMPOSER_VERSION=2.2.5
4

So I can run tests simply via

PHP_IDE_CONFIG=serverName=dofroscra
4

COMPOSER_VERSION=2.2.5
5

Install SSH

We will execute commands from PhpStorm via ssh in the

services:
  service:
    extra_hosts:
      - host.docker.internal:host-gateway
4 container. As mentioned, we won't use a key file for authentication but will instead simply use a password that is configured via the
PHP_IDE_CONFIG=serverName=dofroscra
6 variable in
# File: .docker/images/php/base/Dockerfile

FROM base as local

RUN apk add --no-cache --update \
        php-xdebug~=${TARGET_PHP_VERSION} \
    # ensure that xdebug is not enabled by default
    && rm -f /etc/php8/conf.d/00_xdebug.ini
5 and passed to the image in
# File: .docker/images/php/base/conf.d/zz-app-local.ini

; Note:
; Remove the comment ; to enable debugging
;zend_extension=xdebug
xdebug.client_host=host.docker.internal
xdebug.start_with_request=yes
xdebug.mode=debug
7. In addition, we map port
PHP_IDE_CONFIG=serverName=dofroscra
9 from the host system to port
services:
  php-fpm:
    environment:
      - PHP_IDE_CONFIG=${PHP_IDE_CONFIG?}

  php-worker:
    environment:
      - PHP_IDE_CONFIG=${PHP_IDE_CONFIG?}

  application:
    environment:
      - PHP_IDE_CONFIG=${PHP_IDE_CONFIG?}
0 of the application container and make sure that the codebase is shared as a volume between host and container

COMPOSER_VERSION=2.2.5
6

The container already contains

services:
  php-fpm:
    environment:
      - PHP_IDE_CONFIG=${PHP_IDE_CONFIG?}

  php-worker:
    environment:
      - PHP_IDE_CONFIG=${PHP_IDE_CONFIG?}

  application:
    environment:
      - PHP_IDE_CONFIG=${PHP_IDE_CONFIG?}
1 and sets the password

COMPOSER_VERSION=2.2.5
7

Setup PhpStorm

We will configure a remote PHP interpreter that uses an SSH connection to run commands in the

services:
  service:
    extra_hosts:
      - host.docker.internal:host-gateway
4 container. Before, , which was kinda confusing ("What is SFTP doing here?"), so we will use an SSH Configuration instead and configure the path mappings in the Cli Interpreter interface

SSH Configuration

At

services:
  php-fpm:
    environment:
      - PHP_IDE_CONFIG=${PHP_IDE_CONFIG?}

  php-worker:
    environment:
      - PHP_IDE_CONFIG=${PHP_IDE_CONFIG?}

  application:
    environment:
      - PHP_IDE_CONFIG=${PHP_IDE_CONFIG?}
4 create a new SSH Configuration named "Docker PHP Tutorial" with the following settings

  • Host: 127.0.0.1
  • Port: see
    services:
      php-fpm:
        environment:
          - PHP_IDE_CONFIG=${PHP_IDE_CONFIG?}
    
      php-worker:
        environment:
          - PHP_IDE_CONFIG=${PHP_IDE_CONFIG?}
    
      application:
        environment:
          - PHP_IDE_CONFIG=${PHP_IDE_CONFIG?}
    
    5 in
    # File: .docker/images/php/base/conf.d/zz-app-local.ini
    
    ; Note:
    ; Remove the comment ; to enable debugging
    ;zend_extension=xdebug
    xdebug.client_host=host.docker.internal
    xdebug.start_with_request=yes
    xdebug.mode=debug
    
    7
  • User name: see
    services:
      php-fpm:
        environment:
          - PHP_IDE_CONFIG=${PHP_IDE_CONFIG?}
    
      php-worker:
        environment:
          - PHP_IDE_CONFIG=${PHP_IDE_CONFIG?}
    
      application:
        environment:
          - PHP_IDE_CONFIG=${PHP_IDE_CONFIG?}
    
    7 in
    services:
      php-fpm:
        environment:
          - PHP_IDE_CONFIG=${PHP_IDE_CONFIG?}
    
      php-worker:
        environment:
          - PHP_IDE_CONFIG=${PHP_IDE_CONFIG?}
    
      application:
        environment:
          - PHP_IDE_CONFIG=${PHP_IDE_CONFIG?}
    
    8
  • Authentication type: Password
  • Password: see
    PHP_IDE_CONFIG=serverName=dofroscra
    
    6 in
    # File: .docker/images/php/base/Dockerfile
    
    FROM base as local
    
    RUN apk add --no-cache --update \
            php-xdebug~=${TARGET_PHP_VERSION} \
        # ensure that xdebug is not enabled by default
        && rm -f /etc/php8/conf.d/00_xdebug.ini
    
    5

PHP Interpreter

At

.PHONY: composer
composer: ## Run composer commands. Specify the command e.g. via ARGS="install"
    $(EXECUTE_IN_APPLICATION_CONTAINER) composer $(ARGS);
1 add a new PHP CLI interpreter that uses the new SSH Configuration

Cara menggunakan config debug phpstorm

In addition, we define the path to the xdebug extension because it is disabled by default but PhpStorm can enable it automatically if required. You can find the path in the

services:
  service:
    extra_hosts:
      - host.docker.internal:host-gateway
4 container via

COMPOSER_VERSION=2.2.5
8

We still need to by adding a custom PHP option for

# File: .docker/images/php/base/conf.d/zz-app-local.ini

; Note:
; Remove the comment ; to enable debugging
;zend_extension=xdebug
xdebug.client_host=host.docker.internal
xdebug.start_with_request=yes
xdebug.mode=debug
1. That's the same value we use in
.PHONY: composer
composer: ## Run composer commands. Specify the command e.g. via ARGS="install"
    $(EXECUTE_IN_APPLICATION_CONTAINER) composer $(ARGS);
4.

In the interpreter overview we must now configure the path mappings so that PhpStorm knows "which local file belongs to which remote one". The remote folder is defined in

# File: .docker/images/php/base/Dockerfile

FROM base as local

RUN apk add --no-cache --update \
        php-xdebug~=${TARGET_PHP_VERSION} \
    # ensure that xdebug is not enabled by default
    && rm -f /etc/php8/conf.d/00_xdebug.ini
5 via

COMPOSER_VERSION=2.2.5
9

Afterwards we can set a breakpoint e.g. in

.PHONY: composer
composer: ## Run composer commands. Specify the command e.g. via ARGS="install"
    $(EXECUTE_IN_APPLICATION_CONTAINER) composer $(ARGS);
6 and start debugging:

The screenshot shows that PhpStorm adds the Xdebug extension that we defined previously.

PHPUnit

.PHONY: composer
composer: ## Run composer commands. Specify the command e.g. via ARGS="install"
    $(EXECUTE_IN_APPLICATION_CONTAINER) composer $(ARGS);
7 is configured via
.PHONY: composer
composer: ## Run composer commands. Specify the command e.g. via ARGS="install"
    $(EXECUTE_IN_APPLICATION_CONTAINER) composer $(ARGS);
8. First, we select the interpreter that we just added

Then, we add the paths to the composer autoload script and the

PHP_IDE_CONFIG=serverName=dofroscra
1 configuration file.

PhpStorm will now execute tests using the PHP interpreter in the

services:
  service:
    extra_hosts:
      - host.docker.internal:host-gateway
4 container

Debugging

First of all, if you haven't already please also take a look at the official xdebug documentation. Derick is doing a great job at explaining xdebug in detail including some helpful videos like Xdebug 3: Xdebug with Docker and PhpStorm in 5 minutes

Debug code executed via PhpStorm

This should already work out of the box. Simply set a break point, right-click on a file and choose "Debug '...'"

Debug code executed via php-fpm, cli or from a worker

For code that is executed "directly" by a container without PhpStorm, we first need to enable

# File: .docker/images/php/base/Dockerfile

FROM base as local

RUN apk add --no-cache --update \
        php-xdebug~=${TARGET_PHP_VERSION} \
    # ensure that xdebug is not enabled by default
    && rm -f /etc/php8/conf.d/00_xdebug.ini
9 in the container by removing the
# File: .docker/images/php/base/Dockerfile

# ...

RUN apk add --update --no-cache  \
        php-dom~=${TARGET_PHP_VERSION} \
        php-xml~=${TARGET_PHP_VERSION} \
2 in front of the extension in
# File: .docker/images/php/base/Dockerfile

# ...

RUN apk add --update --no-cache  \
        php-dom~=${TARGET_PHP_VERSION} \
        php-xml~=${TARGET_PHP_VERSION} \
3

services:
  php-base:
    build:
      args:
        - COMPOSER_VERSION=${COMPOSER_VERSION?}
0

To make this a little more convenient, we use dedicated make recipes for those actions in

# File: .docker/images/php/base/Dockerfile

# ...

RUN apk add --update --no-cache  \
        php-dom~=${TARGET_PHP_VERSION} \
        php-xml~=${TARGET_PHP_VERSION} \
4

services:
  php-base:
    build:
      args:
        - COMPOSER_VERSION=${COMPOSER_VERSION?}
1

To capture incoming requests, we need to make PhpStorm listen for PHP Debug connections via

# File: .docker/images/php/base/Dockerfile

# ...

RUN apk add --update --no-cache  \
        php-dom~=${TARGET_PHP_VERSION} \
        php-xml~=${TARGET_PHP_VERSION} \
5.

The corresponding ports are configured at

# File: .docker/images/php/base/Dockerfile

# ...

RUN apk add --update --no-cache  \
        php-dom~=${TARGET_PHP_VERSION} \
        php-xml~=${TARGET_PHP_VERSION} \
6. In Xdebug < 3 the default port was
# File: .docker/images/php/base/Dockerfile

# ...

RUN apk add --update --no-cache  \
        php-dom~=${TARGET_PHP_VERSION} \
        php-xml~=${TARGET_PHP_VERSION} \
7 and in

Finally, we need to add a server via

# File: .docker/images/php/base/Dockerfile

# ...

RUN apk add --update --no-cache  \
        php-dom~=${TARGET_PHP_VERSION} \
        php-xml~=${TARGET_PHP_VERSION} \
9

The name of the server must match the value of the

COMPOSER_VERSION=2.2.5
00 key in the environment variable
# File: .docker/images/php/base/conf.d/zz-app-local.ini

; Note:
; Remove the comment ; to enable debugging
;zend_extension=xdebug
xdebug.client_host=host.docker.internal
xdebug.start_with_request=yes
xdebug.mode=debug
4 that we configured previously as
COMPOSER_VERSION=2.2.5
02.

php-fpm

For

COMPOSER_VERSION=2.2.5
03 we must restart the
COMPOSER_VERSION=2.2.5
03 process without restarting the container after we have activated
# File: .docker/images/php/base/Dockerfile

FROM base as local

RUN apk add --no-cache --update \
        php-xdebug~=${TARGET_PHP_VERSION} \
    # ensure that xdebug is not enabled by default
    && rm -f /etc/php8/conf.d/00_xdebug.ini
9 via

services:
  php-base:
    build:
      args:
        - COMPOSER_VERSION=${COMPOSER_VERSION?}
2

Since this is a pain to remember, we add a make target in

# File: .docker/images/php/base/Dockerfile

# ...

RUN apk add --update --no-cache  \
        php-dom~=${TARGET_PHP_VERSION} \
        php-xml~=${TARGET_PHP_VERSION} \
4

services:
  php-base:
    build:
      args:
        - COMPOSER_VERSION=${COMPOSER_VERSION?}
3

So we can now simply run

services:
  php-base:
    build:
      args:
        - COMPOSER_VERSION=${COMPOSER_VERSION?}
4

Setting a breakpoint in

COMPOSER_VERSION=2.2.5
07 and opening http://127.0.0.1/ in a browser or via
COMPOSER_VERSION=2.2.5
08 will halt the execution as expected.

cli

Instead of triggering a PHP script via HTTP request, we can also run CLI scripts - think of the

COMPOSER_VERSION=2.2.5
09 target for instance. To debug such invocations, we need to follow the same steps as before:

  • enable the
    # File: .docker/images/php/base/Dockerfile
    
    FROM base as local
    
    RUN apk add --no-cache --update \
            php-xdebug~=${TARGET_PHP_VERSION} \
        # ensure that xdebug is not enabled by default
        && rm -f /etc/php8/conf.d/00_xdebug.ini
    
    9 extension in the
    services:
      service:
        extra_hosts:
          - host.docker.internal:host-gateway
    
    4 container
  • "Listening for PHP Debug Connections" from PhpStorm

Running the following make targets will trigger a breakpoint in

.PHONY: composer
composer: ## Run composer commands. Specify the command e.g. via ARGS="install"
    $(EXECUTE_IN_APPLICATION_CONTAINER) composer $(ARGS);
6:

services:
  php-base:
    build:
      args:
        - COMPOSER_VERSION=${COMPOSER_VERSION?}
5

php-workers

And finally the same thing for long running PHP processes (aka workers). Just as before:

  • enable the
    # File: .docker/images/php/base/Dockerfile
    
    FROM base as local
    
    RUN apk add --no-cache --update \
            php-xdebug~=${TARGET_PHP_VERSION} \
        # ensure that xdebug is not enabled by default
        && rm -f /etc/php8/conf.d/00_xdebug.ini
    
    9 extension in the
    COMPOSER_VERSION=2.2.5
    
    14 container
  • "Listening for PHP Debug Connections" from PhpStorm
  • restart the php workers

Running the following make targets will trigger a breakpoint in

COMPOSER_VERSION=2.2.5
15:

services:
  php-base:
    build:
      args:
        - COMPOSER_VERSION=${COMPOSER_VERSION?}
6

strace

strace is a great tool for debugging long running processes that I've adopted after reading What is PHP doing?. I've added it to the php base image:

services:
  php-base:
    build:
      args:
        - COMPOSER_VERSION=${COMPOSER_VERSION?}
7

You can attach to any running process via

COMPOSER_VERSION=2.2.5
16 - BUT that doesn't work out of the box on docker and will fail with the error message

services:
  php-base:
    build:
      args:
        - COMPOSER_VERSION=${COMPOSER_VERSION?}
8

This is caused by a security measure from docker and can be circumvented by adding

services:
  php-base:
    build:
      args:
        - COMPOSER_VERSION=${COMPOSER_VERSION?}
9

in

# File: .docker/images/php/base/conf.d/zz-app-local.ini

; Note:
; Remove the comment ; to enable debugging
;zend_extension=xdebug
xdebug.client_host=host.docker.internal
xdebug.start_with_request=yes
xdebug.mode=debug
7 to all PHP containers. After rebuilding and restarting the docker setup, you can now e.g. log in the
COMPOSER_VERSION=2.2.5
14 container and run
# File: .docker/images/php/base/Dockerfile

FROM base as local

RUN apk add --no-cache --update \
        php-xdebug~=${TARGET_PHP_VERSION} \
    # ensure that xdebug is not enabled by default
    && rm -f /etc/php8/conf.d/00_xdebug.ini
1 on a php worker process:

# File: .docker/images/php/base/Dockerfile

FROM base as local

RUN apk add --no-cache --update \
        php-xdebug~=${TARGET_PHP_VERSION} \
    # ensure that xdebug is not enabled by default
    && rm -f /etc/php8/conf.d/00_xdebug.ini
0

Wrapping up

Congratulations, you made it! If some things are not completely clear by now, don't hesitate to leave a comment. Apart from that, you should now have a fully configured development setup that works with PhpStorm as your IDE.

In the next part of this tutorial, we will use a fresh installation of Laravel on top of our setup.

Please subscribe to the RSS feed or to get automatic notifications when this next part comes out :)


Wanna stay in touch?

Since you ended up on this blog, chances are pretty high that you're into Software Development (probably PHP, Laravel, Docker or Google Big Query) and I'm a big fan of feedback and networking.

So - if you'd like to stay in touch, feel free to shoot me an email with a couple of words about yourself and/or connect with me on LinkedIn or Twitter or simply subscribe to my RSS feed or go the crazy route and subscribe via mail and don't forget to leave a comment :)

Subscribe to posts via mail

Email Address

First Name

We use Mailchimp as our newsletter provider. By clicking subscribe, you acknowledge that your information will be transferred to Mailchimp for processing. Learn more about Mailchimp's privacy practices here.