Skip to content

Commit eb9b797

Browse files
committed
Add Xdebug support to php-fpm service.
1 parent 7370609 commit eb9b797

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

.env.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
### This root .env file is intended to be by both your PHP application and Docker Compose
2+
### This consolidates all application environment variables into an easy-to-find .env file
3+
4+
XDEBUG_ON=false
5+
XDEBUG_REMOTE_HOST=127.0.0.1

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@ To install npm packages, run:
7676

7777
# How-to (advanced)
7878

79+
To enable the Xdebug module:
80+
81+
1. Copy the `.env.example` to an `.env` file and:
82+
1. Change the value of `XDEBUG_ON` to `true`
83+
1. Change the value of `XDEBUG_REMOTE_HOST` to your host machine's IP address.
84+
1. Run `docker-compose up -d --build --remove-orphans` to re-build the service.
85+
86+
---
87+
7988
If you want to extend the functionality of a service (e.g. php-fpm), you have to re-build it.
8089

8190
To accomplish this, modify the Dockerfile, then run:
@@ -90,7 +99,7 @@ If you want to use a different web server port (e.g. 80), modify the port on the
9099
and start the stack again.
91100

92101

93-
## Gotchas
102+
# Gotchas
94103

95104
Ensure that the host machine ports `8080` (web server) and `3306` (database) are open on your host machine.
96105

docker-compose.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ services:
1111
php-fpm:
1212
build:
1313
context: ./services/php
14+
args:
15+
- "XDEBUG_ON=${XDEBUG_ON}"
16+
- "XDEBUG_REMOTE_HOST=${XDEBUG_REMOTE_HOST}"
1417
ports:
1518
- 9000
1619
volumes_from:

services/php/Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,21 @@ RUN docker-php-ext-install opcache && \
2222
docker-php-ext-install mysqli && \
2323
docker-php-ext-install pdo pdo_mysql
2424

25+
# xdebug
26+
ARG XDEBUG_ON=false
27+
ARG XDEBUG_REMOTE_HOST=127.0.0.1
28+
RUN if [ ${XDEBUG_ON} = true ]; then \
29+
pecl install xdebug && \
30+
docker-php-ext-enable xdebug && \
31+
echo "xdebug.default_enable = 0" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && \
32+
echo "xdebug.remote_enable = 1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && \
33+
echo "xdebug.remote_autostart = 0" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && \
34+
echo "xdebug.remote_connect_back = 0" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && \
35+
echo "xdebug.profiler_enable = 0" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && \
36+
echo "xdebug.remote_host = ${XDEBUG_REMOTE_HOST}" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && \
37+
echo "xdebug.remote_port = 9000" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
38+
;fi
39+
2540
# mark volume/s as externally mounted
2641
VOLUME ["/var/www"]
2742

0 commit comments

Comments
 (0)