Skip to content

Commit 678074f

Browse files
Merge pull request #4 from michaelperrin/feature/xdebug
Add Xdebug configuration
2 parents 649f7fe + a1fb03f commit 678074f

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

README.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,36 @@
1-
Docker configuration to
1+
Docker configuration to run a Symfony app.
22

33
## Run
44

55
docker-compose up -d
66

77
You can now visit http://localhost and see the default Symfony page.
8+
9+
## Useful commands
10+
11+
Symfony commands:
12+
13+
docker-compose exec php bin/console
14+
15+
16+
## Included stuff
17+
18+
### Xdebug
19+
20+
Making Xdebug working with Docker is quite tricky as there is currently a limitation to Docker for Mac
21+
that prevents a container to make a request to the the host, which is exactly what we would like to do with Xdebug.
22+
23+
To make Xdebug debugging work, you will first need to run this command:
24+
25+
sudo ifconfig lo0 alias 10.200.10.1/24
26+
27+
This IP address is configured in the environment variables of the PHP container (see `docker-compose.yml` file).
28+
29+
No extra configuration is needed in your IDE (tested on Sublime Text, Visual Studio Code and Atom), apart the usual.
30+
31+
Interesting resources:
32+
33+
* https://docs.docker.com/docker-for-mac/networking/#/use-cases-and-workarounds
34+
* http://blog.arroyolabs.com/2016/10/docker-xdebug/
35+
* http://joenyland.me/blog/debug-a-php-app-in-a-docker-container-using-xdebug/
36+

docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ services:
44
build: ./docker/php/
55
environment:
66
TIMEZONE: Europe/Paris
7+
XDEBUG_REMOTE_HOST: 10.200.10.1
78
volumes:
89
- ./docker/php/php.ini:/usr/local/etc/php/conf.d/php.ini:ro
10+
- ./docker/php/xdebug.ini:/usr/local/etc/php/conf.d/xdebug.ini:ro
911
- ./app:/var/www/app
1012
working_dir: /var/www/app
1113

docker/php/Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,7 @@ RUN mv composer.phar /usr/local/bin/composer
3838
RUN curl "https://phar.phpunit.de/phpunit.phar" -L -o "phpunit.phar"
3939
RUN chmod +x phpunit.phar
4040
RUN mv phpunit.phar /usr/local/bin/phpunit
41+
42+
# Xdebug
43+
RUN pecl install xdebug \
44+
&& docker-php-ext-enable xdebug

docker/php/xdebug.ini

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
xdebug.remote_enable = 1
2+
xdebug.remote_autostart = 1
3+
xdebug.remote_host = ${XDEBUG_REMOTE_HOST}
4+
xdebug.remote_port = 9000
5+
xdebug.remote_log=/var/log/xdebug/remote.log

0 commit comments

Comments
 (0)