Docker Phpstorm



Docker Phpstorm

Hello,

I’m a bit confused using xdebug, docker for windows, and phpstorm…

i have xdebug configured in a container with PHP.
Here is what appears in my php.ini from within this container :

Phpunit docker phpstorm tests Setup a Let's Encrypt certificate in a AWS Elastic Load Balancer Managing PUT requests with file uploads in psr-7 and middleware PHP applications.

from this container i can’t access directly my Windows host IP, but i can access two IPs :
the docker host IP which is 172.17.0.1
and the docker IP i have from Windows (resolving docker) which is 10.0.75.2
why is there so many IPs ? what are there referring to exactly ?
i even can ping 10.0.75.1 which might be some virtual bridge of some kind ?

With the new Docker integration plugin for PhpStorm, you can add Docker support to existing projects, view logs, manage Docker containers, and debug PHP web applications from right inside PhpStorm. First of all, you’ll need to install Docker and related tools so that you can take advantage of the Docker integration in PhpStorm. Hi, I have been struggling for the last two hours with phpStorm + xDebug + Docker in Windows 10 and I am not able to make the debugging to work. I am running the following software version: PhpStorm 2017.2.2 EAP; Windows 10.0.15063.0; Docker CE Edge 17.07.0-ce-rc1-win21 (12927) I have setup the IDE as follow.

xdebug communicates on port 9000. i have bind port 9000 to 9000 for this container :

from my understanding this binds port 9000 from this container to port 9000 on 10.0.75.2 (docker from windows) ?
then what IP should i use for xdebug.remote_host ?
by default PHPStorm waits for some connection on port 9000, on local machine (Windows).
should I set what it calls a DBGp Proxy ? Pointing to docker ? On port 9000 ?

for now i have tried xdebug.remote_host with 172.17.0.1 , 10.0.75.2 or localhost and could not get it to work yet.

Skip to end of metadataGo to start of metadata

Redirection Notice

Icon
This page will redirect to https://www.jetbrains.com/help/phpstorm/docker.html in about 2 seconds.
Icon

Docker is an open platform for building, shipping and running distributed applications. It gives programmers, development teams and operations engineers the common toolbox they need to take advantage of the distributed and networked nature of modern applications.

This tutorial describes Docker support in PhpStorm, which includes debugging PHP web applications (running in the Docker container), inspecting, managing containers and viewing running processes.You can also search through logs, start and stop containers, and perform basic container management.

  • Prerequisites
  • PhpStorm & Docker Integration Configuration
  • Working with Docker in PhpStorm

Docker Xdebug

Docker installation

First of all, you'll need to install Docker and related tools so that you can take advantage of the Docker integration in PhpStorm. Please refer to the Docker documentation to get more information about the installation process:

  • Installing Docker engine on Windows;
  • Installing Docker engine on Mac OS X;
  • Installing Docker engine on Linux (Ubuntu, other distributions-related instructions are available as well);
  • You can also install Docker on various cloud platforms (e.g. read tutorials on installing Docker on Amazon EC2, Google Cloud Platform, and Microsoft Azure).

Docker plugin is bundled in PhpStorm since 2016.3.

Prerequisites for Mac for PhpStorm 2016.3 and below.

  1. Use the standard MacOSX terminal to execute asocat TCP-LISTEN:2375,reuseaddr,fork,bind=localhost UNIX-CONNECT:/var/run/docker.sockcommand to allow older versions of PhpStorm to connect to Docker;

    1. install socat as described at http://macappstore.org/socat/
    2. run socat TCP-LISTEN:2375,reuseaddr,fork,bind=localhost UNIX-CONNECT:/var/run/docker.sock
    3. enter tcp://localhost:2375 as an API URL in IDE
    4. (note: you may use any other port instead of 2375)


    Note: Since PhpStorm 2017.1 you can connect via Unix socket directly.

Configuring PhpStorm to work with Docker

  1. Open Settings / Preferences | Build, Execution, Deployment | Docker and create Docker configuration with a + button.
  2. You should provide the configuration name (Docker in our case), API URL (tcp://localhost:2375for Windows and for Mac OS X if using PhpStorm older than 2017.1, unix:///var/run/docker.sock for Mac OS X and Linux).

  3. Apply the configuration and close the Settings / Preferences dialog.
  4. Create a new Docker DeploymentRun/Debug Configuration invoking the dialog from the Run | Edit configurations.. menu:
    Then, create a Docker Deployment configuration with a + button:
  5. Provide all the necessary parameters on the Deployment tab. In our case we've provided Run/Debug Configuration Name (Start Docker in our case), selected the server (Docker), selected the Deployment method to be Dockerfile, provided Image tag (mysite) and Container name (Docker_Xdebug):

  6. Provide all the necessary parameters and configurations on the Container tab. At this point we are interested in exposing port 80 of the container to be available from our local machine, so we should configure a port binding for that (Container port: 80, Protocol: tcp, Host IP: empty, Host port: 8080):
    In addition, we can configure links, volume bindings, environment variables, and much more.

  7. Apply the Run/Debug Configuration and close the dialog.
Icon

At this step it's important to note that that there are many ways to create/configure Docker containers and VM images, and we'd recommend to always refer to the Docker documentation on the official web site.

For the purposes of this tutorial we're using Dockerfile and Apache configuration file. We've also created an index.php file with phpinfo(); to be deployed to the Docker container. We're making some significant configuration in those Dockerfile and Apache configuration file, so you're recommended to have a look at them. You can download entire project used in this demo or separate config files (apache-config.conf, Dockerfile) which then need to be placed in the project root folder.

Running the Docker from PhpStorm

As all the tools are installed, and the integration is configured, the recently created Start Docker Run/Debug Configuration can be launched:

The Application Servers tool window will be opened updating you on the provisioning status and current state of all your Docker containers:

As soon as the process is completed, and our Docker_Xdebug container status turns green, we can check how it works in the browser. You should be able to open it by the URL http://localhost:8080/. If you can't see the index.php execution results in the browser (containing phpinfo(); in our case), please check that you have specified the correct port bindings on the previous steps.

In our example, everything is running fine on the port we've expected the web app to be:

Managing Docker containers and other Docker-related actions in PhpStorm

From the Application Servers tool window, it’s easy to inspect containers and view running processes. You can also search through logs, start and stop containers, and perform basic container management like creating and deleting containers. Each deployment in Docker is assigned a unique container ID - these are initially temporary containers, although they can be committed and saved for further distribution. On the Docker Hub registry, there are many such images available for you to try.

Phpstorm

Images in Docker are read-only - once committed, any changes to a container’s state will become part of a new image. When you have a stable build on one instance of Docker (on your development machine, staging server, or a cloud), reproducing the exact same build is as simple as (1) committing the Docker container, (2) pushing it to a registry (public or private), then (3) pulling the same image to another instance of Docker, running - wherever.

Debugging the PHP web application running in the Docker container

Assuming that you already run the Docker container now (and everything worked well on the previous steps), you should now able to open your PHP web application in the browser by http://host:port URL (http://localhost:8080/ in our case). The major difficulty in getting Xdebug (or Zend Debugger) working with PhpStorm and Docker integration is the correct configuration of the Docker container. Gemalto port devices driver download.

In our case we're using a Dockerfile (we've already shown this config earlier and provided links to download it) to configure the container, including Xdebug-specific parameters, such as:

In the example above we're modifying /etc/php/7.0/apache2/php.ini providing a path to Xdebug extension, and some other Xdebug parameters (remote_enable and remote_host). Please note that xdebug.remote_host value should be replaced with your local machine IP address which is visible from the Docker container (where PhpStorm is running, 192.168.2.117 in our case).

Docker Phpstorm Xdebug Phpunit

Configuration for Zend Debugger is similar, please see a full tutorial on installing Xdebug and installing Zend Debugger (there's much more information on required parameters and options).

Don't forget to re-run Start Docker Run/Debug Configuration so that all the changes are applied.

Phpstorm Docker Phpunit

As soon as all the configs are in place, the debugging process can be triggered following this tutorial from step 2 (start Listening for PHP Debug Connections, set a breakpoint in the source code, start a debug session in the browser, reload the current page, debug) to get the debugger up and running in a few moments: Direct color driver download for windows 10.