Debugging Web Applications In PHPStorm With Xdebug And Docker

From Littledamien Wiki
Revision as of 12:34, 10 May 2018 by Video8 (talk | contribs)
Jump to navigation Jump to search

Overview

How to debug a PHP web application in PHPStorm using Docker and XDebug. [1] [2]

PHP configuration

Docker server

Preferences > Language & Frameworks > PHP > Servers

Click the "plus" icon to create a new server.

  • Name: docker
  • Host: localhost
  • Port: 80
  • Debugger: Xdebug
  • Use path mappings: checked

Then under path mappings create associations between project files and their respective locations in the Docker container, e.g.:

The host and port reference host and port within the Docker container. This applies to the path mappings as well.

The container's HTML root is /var/www/html. This path may or may not exist on the local file system, but that doesn't impact anything here.

Two project file directories cannot point to the same path on the server (e.g. bfhhand_web and common_lib can't coexist in the same root directory as they do on production.)

Run configuration

Run > Edit Configurations...

Click the "plus" icon to create a new Debug Configuration.

Select PHP Remote Debug

  • Name: docker
  • Server: docker-server
  • IDE key: docker

docker-server is the server that was created in the previous step.

The value of the IDE Key must match the value that is put into the xdebug.ini file that is created later in the process.

See also