PhpStorm DockerSupportinPhpStorm 200116 0030 2498

download PhpStorm DockerSupportinPhpStorm 200116 0030 2498

of 12

Transcript of PhpStorm DockerSupportinPhpStorm 200116 0030 2498

  • 7/25/2019 PhpStorm DockerSupportinPhpStorm 200116 0030 2498

    1/12

    Docker Support in PhpStorm

    PrerequisitesDocker installationDocker integration plugin installation

    PhpStorm & Docker Integration ConfigurationLaunching default docker machine and getting necessary parameters (Windows / Mac OS X)Launching default docker machine and getting necessary parameters (Linux)

    Configuring PhpStorm to work with DockerWorking with Docker in PhpStorm

    Running the Docker from PhpStormManaging Docker containers and other Docker-related actions in PhpStormDebugging the PHP web application running in the Docker container

    Prerequisites

    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 tothe to get more information about the installation process:Docker documentation

    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 Platformand ).Microsoft Azure

    Docker integration plugin installation

    You will also need to install the plugin in PhpStorm. Open , and click theDocker integration Settings / Preferences | Plugins Install JetBrains button:plugin...

    Tweet

    Dockeris an open platform for building,shipping and running distributed applications. Itgives programmers, development teams andoperations engineers the common toolbox they

    need to take advantage of the distributed andnetworked nature of modern applications.

    This tutorial describes support inDockerPhpStorm, which includes debugging PHP webapplications (running in the Docker container),inspecting, managing containers and viewingrunning processes.You can also search throughlogs, start and stop containers, and perform basic container management.

    https://docs.docker.com/https://docs.docker.com/installation/windows/https://docs.docker.com/installation/mac/https://docs.docker.com/installation/ubuntulinux/http://docs.aws.amazon.com/AmazonECS/latest/developerguide/docker-basics.htmlhttps://cloud.google.com/compute/docs/containershttps://azure.microsoft.com/en-us/documentation/articles/virtual-machines-docker-vm-extension/https://twitter.com/sharehttps://www.docker.com/https://www.docker.com/https://www.docker.com/https://www.docker.com/https://twitter.com/sharehttps://azure.microsoft.com/en-us/documentation/articles/virtual-machines-docker-vm-extension/https://cloud.google.com/compute/docs/containershttp://docs.aws.amazon.com/AmazonECS/latest/developerguide/docker-basics.htmlhttps://docs.docker.com/installation/ubuntulinux/https://docs.docker.com/installation/mac/https://docs.docker.com/installation/windows/https://docs.docker.com/
  • 7/25/2019 PhpStorm DockerSupportinPhpStorm 200116 0030 2498

    2/12

    Search for and install the plugin from the context menu:Docker Docker Integration

    Restart the IDE to complete the installation of the plugin.

  • 7/25/2019 PhpStorm DockerSupportinPhpStorm 200116 0030 2498

    3/12

    1.

    2.

    3.

    1.2.

    a.

    b.

    1.

    PhpStorm & Docker Integration Configuration

    At this point you have Docker and Docker plugin for PhpStorm installed, so we can start with integration configuration.

    Launching default docker machine and getting necessary parameters

    (Windows / Mac OS X)

    Open the application;Docker Quickstart Terminal

    Docker will launch a VM providing output in the console:default

    Run console command to get all the necessary parameters, as we'll need them later for PhpStormdocker-machine env default

    configuration (such as and optional ):DOCKER_HOST DOCKER_CERT_PATH

    Please refer to the to learn more on how the IP address is assigned, and other networkingDocker Networking Documentation

    configuration issues.

    Launching default docker machine and getting necessary parameters (Linux)

    Use the standard Linux terminal to execute a sudo docker run hello-world command to start Docker;You'll need two parameters of your Docker environment to configure PhpStorm at the next steps:

    which is a standard Host IP address, always the same on Linux ( ), please refer to theDOCKER_HOST 172.17.42.1 Dockerto learn more;Networking Documentation

    (optional) DOCKER_CERT_PATH (see more information in the ).documentation

    Configuring PhpStorm to work with Docker

    Open and create with a button:Settings / Preferences | Build, Execution, Deployment | Clouds Docker configuration +

    https://docs.docker.com/articles/networking/https://docs.docker.com/articles/networking/https://docs.docker.com/articles/networking/https://docs.docker.com/articles/https/https://docs.docker.com/articles/https/https://docs.docker.com/articles/networking/https://docs.docker.com/articles/networking/https://docs.docker.com/articles/networking/
  • 7/25/2019 PhpStorm DockerSupportinPhpStorm 200116 0030 2498

    4/12

    2. You should provide the ( in our case), (configuration name Docker API URL https://192.168.99.100:2376 in our case, we've got it on the), (optional,previous step. Please note the protocol change, has been changed totcp https Certificates folder /Users/mikhailvink/.docker/

    in our case):machine/machines/default

    Please note that you will need to provide a in the field on Linux machines instead of the (usually it'ssocket path API URL URLby default):unix:///var/run/docker.sock

  • 7/25/2019 PhpStorm DockerSupportinPhpStorm 200116 0030 2498

    5/12

    3.

    4.

    Apply the configuration and close the dialog.Settings / Preferences

    Create a new invoking the dialog from the menu:Docker DeploymentRun/Debug Configuration Run | Edit configurations...

    Then, create a configuration with a button:Docker Deployment +

  • 7/25/2019 PhpStorm DockerSupportinPhpStorm 200116 0030 2498

    6/12

    5.

    6.

    Provide all the necessary parameters on the tab. In our case we've provided ( iDeployment Run/Debug Configuration Name Start Docker n our case), selected the server ( ), selected the method to be , provided Image tag ( ) and ContainerDocker Deployment Dockerfile mysite name ( ):Docker_Xdebug

    Provide all the necessary parameters and configurations on the tab. At this point we are interested in exposing port 80 of theContainercontainer 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

  • 7/25/2019 PhpStorm DockerSupportinPhpStorm 200116 0030 2498

    7/12

    7.In addition, we can configure links, volume bindings, environment variables, and much more.Apply the and close the dialog.Run/Debug Configuration

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

    For the purposes of this tutorial we're using and . We've also created an file withDockerfile Apache configuration file index.php 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 or separate config files (download entire project used in this demo apache-con, ) which then need to be placed in the project root folder.fig.conf Dockerfile

    https://docs.docker.com/https://confluence.jetbrains.com/download/attachments/70747197/docker_project.zip?version=1&modificationDate=1446162676000&api=v2https://confluence.jetbrains.com/download/attachments/70747197/apache-config.conf?version=1&modificationDate=1446162700000&api=v2https://confluence.jetbrains.com/download/attachments/70747197/apache-config.conf?version=1&modificationDate=1446162700000&api=v2https://confluence.jetbrains.com/download/attachments/70747197/Dockerfile?version=1&modificationDate=1446162711000&api=v2https://confluence.jetbrains.com/download/attachments/70747197/Dockerfile?version=1&modificationDate=1446162711000&api=v2https://confluence.jetbrains.com/download/attachments/70747197/apache-config.conf?version=1&modificationDate=1446162700000&api=v2https://confluence.jetbrains.com/download/attachments/70747197/apache-config.conf?version=1&modificationDate=1446162700000&api=v2https://confluence.jetbrains.com/download/attachments/70747197/docker_project.zip?version=1&modificationDate=1446162676000&api=v2https://docs.docker.com/
  • 7/25/2019 PhpStorm DockerSupportinPhpStorm 200116 0030 2498

    8/12

    Working with Docker in PhpStorm

    Running the Docker from PhpStorm

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

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

    showing a full process)gif

    https://confluence.jetbrains.com/download/attachments/70747197/docker_run.gif?version=1&modificationDate=1446164688000&api=v2https://confluence.jetbrains.com/download/attachments/70747197/docker_run.gif?version=1&modificationDate=1446164688000&api=v2https://confluence.jetbrains.com/download/attachments/70747197/docker_run.gif?version=1&modificationDate=1446164688000&api=v2https://confluence.jetbrains.com/download/attachments/70747197/docker_run.gif?version=1&modificationDate=1446164688000&api=v2
  • 7/25/2019 PhpStorm DockerSupportinPhpStorm 200116 0030 2498

    9/12

    As soon as the process is completed, and our container status turns we can check how it works in the browser. YouDocker_Xdebug green,

    should be able to open it by the URL similar to ( is an IP address of the default Docker machine,http://192.168.99.100:8080/ 192.168.99.100

    we've looked into where to get this parameter before). If you can't see the execution results in the browser (containing in ourindex.php phpinfo();

    case), please check that you have specified the correct IP address and port bindings on the previous steps.

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

  • 7/25/2019 PhpStorm DockerSupportinPhpStorm 200116 0030 2498

    10/12

    Managing Docker containers and other Docker-related actions in PhpStorm

    From the tool window, its easy to inspect containers and view running processes. You can also search through logs, start andApplication Serversstop containers, and perform basic container management like creating and deleting containers. Each deployment in Docker is assigned a uniquecontainer ID - these are initially temporary containers, although they can be and saved for further distribution. On thecommitted Docker Hub

    , there are many such images available for you to try.registry

    https://docs.docker.com/articles/basics/#committing-saving-a-container-statehttps://registry.hub.docker.com/https://registry.hub.docker.com/https://registry.hub.docker.com/https://registry.hub.docker.com/https://docs.docker.com/articles/basics/#committing-saving-a-container-state
  • 7/25/2019 PhpStorm DockerSupportinPhpStorm 200116 0030 2498

    11/12

    Images in Docker are read-only - once committed, any changes to a containers state will become part of a new image. When you have a stablebuild on one instance of Docker (on your development machine, staging server, or a cloud), reproducing the exact same build is as simple as (1) c

    the Docker container, (2) it to a registry (public or private), then (3) the same image to another instance of Docker,ommitting pushing pullingrunning - 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 yourPHP web application in the browser by URL ( in our case). The major difficulty in getting Xdebug (orhttp://host:port http://192.168.99.100:8080/Zend Debugger) working with PhpStorm and Docker integration is the correct configuration of the Docker container.

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

    #Set up debuggerRUN echo "zend_extension=/usr/lib/php5/20131226/xdebug.so" >>

    /etc/php5/apache2/php.ini

    RUN echo "xdebug.remote_enable=1" >> /etc/php5/apache2/php.ini

    #Please provide your host (local machine IP) instead of 192.168.2.117

    RUN echo "xdebug.remote_host=192.168.2.117" >> /etc/php5/apache2/php.ini

    In the example above we're modifying providing a path to Xdebug extension, and some other Xdebug parameters (/etc/php5/apache2/php.ini remand ). Please note that value should be replaced with your local machine IP addressote_enable remote_host xdebug.remote_host which is visible

    (where PhpStorm is running, in our case).from the Docker container 192.168.2.117

    https://docs.docker.com/reference/commandline/cli/#commithttps://docs.docker.com/reference/commandline/cli/#commithttps://docs.docker.com/reference/commandline/cli/#pushhttps://docs.docker.com/reference/commandline/cli/#pullhttps://docs.docker.com/reference/commandline/cli/#pullhttps://docs.docker.com/reference/commandline/cli/#pushhttps://docs.docker.com/reference/commandline/cli/#commithttps://docs.docker.com/reference/commandline/cli/#commit
  • 7/25/2019 PhpStorm DockerSupportinPhpStorm 200116 0030 2498

    12/12

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

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

    As soon as all the configs are in place, the debugging process can be triggered following from (startthis tutorial step 2 Listening for PHP Debugset a breakpoint in the source code, start a debug session in the browser, reload the current page, debug) to get the debugger upConnections,

    and running in a few moments:

    Tweet

    https://confluence.jetbrains.com/display/PhpStorm/Xdebug+Installation+Guidehttps://confluence.jetbrains.com/display/PhpStorm/Zend+Debugger+Installation+Guidehttps://confluence.jetbrains.com/display/PhpStorm/Zero-configuration+Web+Application+Debugging+with+Xdebug+and+PhpStormhttps://twitter.com/sharehttps://twitter.com/sharehttps://confluence.jetbrains.com/display/PhpStorm/Zero-configuration+Web+Application+Debugging+with+Xdebug+and+PhpStormhttps://confluence.jetbrains.com/display/PhpStorm/Zend+Debugger+Installation+Guidehttps://confluence.jetbrains.com/display/PhpStorm/Xdebug+Installation+Guide