@@ -23,6 +23,79 @@ For instance, use the following command to use the `master` branch of Symfony:
23
23
24
24
` STABILITY=dev docker-compose up --build `
25
25
26
+ ## Debugging
27
+
28
+ The default Docker stack is shipped without a Xdebug stage. It's easy
29
+ though to add [ Xdebug] ( https://xdebug.org/ ) to your project, for development
30
+ purposes such as debugging tests or API requests remotely.
31
+
32
+ ### Add a Development Stage to the Dockerfile
33
+
34
+ To avoid deploying Symfony Docker to production with an active Xdebug extension,
35
+ it's recommended to add a custom stage to the end of the ` Dockerfile ` .
36
+
37
+ ``` Dockerfile
38
+ # Dockerfile
39
+ FROM symfony_docker_php as symfony_docker_php_dev
40
+
41
+ ARG XDEBUG_VERSION=2.6.0
42
+ RUN set -eux; \
43
+ apk add --no-cache --virtual .build-deps $PHPIZE_DEPS; \
44
+ pecl install xdebug-$XDEBUG_VERSION; \
45
+ docker-php-ext-enable xdebug; \
46
+ apk del .build-deps
47
+ ```
48
+
49
+ ### Configure Xdebug with Docker Compose Override
50
+
51
+ Using an [ override] ( https://docs.docker.com/compose/reference/overview/#specifying-multiple-compose-files )
52
+ file named ` docker-compose.override.yaml ` ensures that the production
53
+ configuration remains untouched.
54
+
55
+ As example, an override could look like this:
56
+
57
+ ``` yaml
58
+ version : ' 3.4'
59
+
60
+ services :
61
+ php :
62
+ build :
63
+ context : .
64
+ target : symfony_docker_php_dev
65
+ environment :
66
+ # See https://docs.docker.com/docker-for-mac/networking/#i-want-to-connect-from-a-container-to-a-service-on-the-host
67
+ # See https://github.com/docker/for-linux/issues/264
68
+ # The `remote_host` below may optionally be replaced with `remote_connect_back`
69
+ XDEBUG_CONFIG : >-
70
+ remote_enable=1
71
+ remote_host=host.docker.internal
72
+ remote_port=9001
73
+ idekey=PHPSTORM
74
+ # This should correspond to the server declared in PHPStorm `Preferences | Languages & Frameworks | PHP | Servers`
75
+ # Then PHPStorm will use the corresponding path mappings
76
+ PHP_IDE_CONFIG : serverName=symfony-docker
77
+ ` ` `
78
+
79
+ And run :
80
+ ` ` ` ` bash
81
+ docker-compose -f docker-compose.yaml -f docker-compose.override.yaml up -d
82
+ ` ` ` `
83
+
84
+ ### Troubleshooting
85
+
86
+ Inspect the installation with the following command. The requested Xdebug
87
+ version should be displayed in the output.
88
+
89
+ ` ` ` bash
90
+ $ docker-compose exec php php --version
91
+
92
+ PHP 7.2.8 (cli) (built : Jul 21 2018 08:09:37) ( NTS )
93
+ Copyright (c) 1997-2018 The PHP Group
94
+ Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
95
+ with Zend OPcache v7.2.8, Copyright (c) 1999-2018, by Zend Technologies
96
+ with Xdebug v2.6.0, Copyright (c) 2002-2018, by Derick Rethans
97
+ ```
98
+
26
99
## Credits
27
100
28
101
Created by [ Kévin Dunglas] ( https://dunglas.fr ) and sponsored by [ Les-Tilleuls.coop] ( https://les-tilleuls.coop ) .
0 commit comments