Skip to content

Commit

Permalink
Inital commit
Browse files Browse the repository at this point in the history
  • Loading branch information
angristan committed May 4, 2019
0 parents commit ff7f448
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM php:7-apache

RUN pecl install xdebug \
&& docker-php-ext-enable xdebug \
&& echo "xdebug.remote_enable=1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
# host.docker.internal does not work on Linux yet: https://github.com/docker/for-linux/issues/264
# Workaround:
# ip -4 route list match 0/0 | awk '{print $3 " host.docker.internal"}' >> /etc/hosts \
&& echo "xdebug.remote_host=host.docker.internal" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

# An IDE key has to be set, but anything works, at least for PhpStorm and VS Code...
ENV XDEBUG_CONFIG="xdebug.idekey=''"
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# 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](https://marketplace.visualstudio.com/items?itemName=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:

![](https://i.imgur.com/B8dnAj7.png)

## 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:

![](https://i.imgur.com/05hPG89.png)

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

![](https://i.imgur.com/Z846Zoh.png)

And then magic happens:

![](https://i.imgur.com/yUnpilx.png)

Enjoy 👋
11 changes: 11 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: "3.7"

services:
sample-app:
build: '.'
ports:
- 127.0.0.1:8080:80
volumes:
- ./:/var/www/html/
# environment:
# - XDEBUG_CONFIG="xdebug.idekey=''"
4 changes: 4 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php

// Put a breakpoint here to test
phpinfo();

0 comments on commit ff7f448

Please sign in to comment.