Docker Php With Xdebug



  1. Docker Php Xdebug Remote Host
  2. Docker Php Ext Enable
  3. Docker Php Xdebug Vscode

Step Two: Configuring Xdebug. Before Docker, Xdebug was relatively straightforward to configure on a platform, in that it was a new set of the php.ini parameters – you’d either just edit the existing php.ini, or load in a custom ini or override. Instruct XDebug to connect to host.docker.internal for command line execution or whenever “connect back” is not possible. Set PHPIDECONFIG env variable to serverName=localhost. This will tell your PhpStorm which server configuration to use. See next step for details. Keep in mind that PHPStorm opens port 9000 (by default) so Xdebug can connect to it. Our PHP container has Xdebug installed and Xdebug will try to connect to PHPStorm on port 9000 by default. Out of the box, everything should be fine. Except if port 9000 is already taken by another program on your host (your machine running PHPStorm). I assume you have a basic Knowledge of Docker, PHP and XDebug. You can clone this repository as base to follow this gude as it contains a basic Symfony Flex application with all the Docker stuff explained in this article included. Step 1 - Dockerize the application Of course, to be able to use Xdebug you must install it on your Docker container.

FeaturesNewsletterTutorials

So, you’ve decided to try something new today and started a project from scratch. Your first step will be to set up a development environment: at the bare minimum, you’d want to run a web server and a PHP interpreter (preferably – with the debugging engine installed).

With Docker, you can start developing, running, and debugging your code in a matter of minutes!

Probably the easiest way to integrate Docker with PhpStorm is to use the PhpStorm Docker registry. It provides a selection of preconfigured Docker images curated by the PhpStorm team, which cover the most common PHP development needs.

Before you proceed, make sure that you have Docker installed on your machine: see how to do it on Windows and on macOS.

Defining the environment

To get started, we create a new project in PhpStorm. Next, we create a new file named docker-compose.yml , which will describe the configuration of the services comprising our app. In our case, it will be a single webserver service:
As you can see, we use the preconfigured Docker image comprising the Apache web server and PHP 7.1 with Xdebug.

Note that we use the host.docker.internal value to refer to the remote host. In Docker for Windows and Docker for Mac, it automatically resolves to the internal address of the host, letting you easily connect to it from the container.

Docker Php Xdebug Remote Host

An important note for Linux users: host.docker.internal on Linux is currently not supported. You’ll have to use your local machine’s hostname instead (to find out what your machine’s hostname is, simply execute hostname in Terminal).

Docker Php With Xdebug

The corresponding environment configuration section for Linux will read as follows:
See here for more details and possible workarounds.

Docker Php With Xdebug

Our environment is fully described:

We can now start using it by creating a dedicated run/debug configuration.

Creating a run/debug configuration

Right-click docker-compose.yml and select Create… from the context menu:

In the dialog that opens, provide the name of the configuration and apply your changes:

You can now start the configuration from the toolbar:

PhpStorm will automatically download the required image and start the web server:

That’s it: we’ve got everything ready for running and debugging our code!

Running and debugging code

Let’s ensure that everything works as expected. To do this, we’ll create the most simple Hello world PHP file and try to debug it following the PhpStorm Zero-Configuration Debugging approach.

Since we already have Xdebug installed and configured, this will only require that you:

  • Have a debugging extension installed and enabled for your browser:
  • Set a breakpoint in your code:
  • Enable listening to incoming debug connections in PhpStorm:

Now, simply open the page in the browser, and the debugging session will be started automatically:

Docker Php Ext Enable

We encourage you to further explore the PhpStorm Docker registry: while we’ve looked at a very simple case, you can use the described technique to provide your environment with, for example, a database, or an sftp server.
Using these Docker images will save you a lot of effort and let you start coding in a matter of a minute, or even less!

SshDocker php xdebug vscode

Docker Php Xdebug Vscode

If you’d like to learn more about Docker and how to use it in PhpStorm, make sure to check out the excellent tutorial series by Pascal Landau, and PhpStorm documentation, of course.

Your JetBrains PhpStorm Team
The Drive to Develop