Setting up Xdebug with Docker and PHPStorm

In this article we’ll discuss how to set up Xdebug with Docker and PHPStorm. To keep it nice and simple we’ll only discuss the most basic parts that are needed to get this setup up and running.

1. Dockerfile configuration

FROM php:7.1-fpm

# Install xdebug
RUN pecl install xdebug \
    && docker-php-ext-enable xdebug

# Include configurations (dev.ini)
COPY ./conf.d/* /usr/local/etc/php/conf.d/

We’re using the official php repository to get our base image from. Next we’re installing and enabling xdebug. And the third part is to include our own dev.ini which we will create in step 2.

2. Create dev.ini


xdebug.remote_enable = On
xdebug.remote_host = docker.for.mac.localhost
xdebug.remote_connect_back = 0
xdebug.remote_port = 9000
xdebug.idekey = PHPSTORM


xdebug.remote_enable = On
xdebug.remote_connect_back = 1
xdebug.remote_port = 9000
xdebug.idekey = PHPSTORM

Here we are setting the properties that allow the docker host to connect with xdebug. The highlighted lines show the difference between the Mac and Linux configuration. Both of them allow you to connect to the host without a cumbersome process to retrieve the host ip and put it in the dev.ini.

3. Modify docker-compose.yml

      - php/php.env

Load up our environment variables (to be created in the next step)

4. Create php.env


To tell PHPStorm which of the configured servers we’re targeting environment variable PHP_IDE_CONFIG is used. We’ll create this server in the next step.

5. Configure PHPStorm server

We are now creating a new server in PHPStorm (Settings -> Languages & Frameworks -> PHP -> Servers). Click the plus sign and enter the serverName from the previous step in the name field. Then configure the port and mapping conform your existing project configuration are you’re all set!

Happy debugging!

Nick Stemerdink
Geen reactie's

Geef een reactie