-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ff7f448
Showing
4 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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=''" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 👋 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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=''" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?php | ||
|
||
// Put a breakpoint here to test | ||
phpinfo(); |