zawtunlatt / php-xdebug-docker

Debug PHP with Xdebug inside Docker. Tested with PhpStorm and VS Code.

Home Page:https://stanislas.blog/debug-php-docker-xdebug-vscode-phpstorm/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PHP/Xdebug/Docker example

Debug PHP with Xdebug inside Docker. Tested with PhpStorm and VS Code.

Usage

The Xdebug config happens in the Dockerfile. I recommend to look at it, escpeially the comments. The most important part is the xdebug.remote_host which has to be set to the Docker host.

A sample docker-compose.yml comes along with it so you can get this up and running in one command: docker-compose up --build -d.

VS Code configuration

Install the felixfbecker.php-debug extension.

You can create a debug configuration by going to Debug > Add Configuration... > PHP, but I've included the .vscode/launch.json file in the repo, with the correct folder maping.

Add a breakpoint, and click on "Listen for XDebug" in the top left hand corner. Load your page, and you should get debugging information:

PhpStorm configuration

You should not have to configure anything since we use the default debug port etc.

Add a breakpoint and start listening for Xdebug in the top right hand corner:

Load your page. PhpStorm will prompt you to add a "server" with a folder mapping:

And then magic happens:

Enjoy đź‘‹

About

Debug PHP with Xdebug inside Docker. Tested with PhpStorm and VS Code.

https://stanislas.blog/debug-php-docker-xdebug-vscode-phpstorm/


Languages

Language:Dockerfile 92.4%Language:PHP 7.6%