Skip to content

Commit ddb78f0

Browse files
Load xdebug on demand for VSCode and Docker (#2278)
* Add script to load xdebug on demand * Load docker xdebug ondemand via vscode * Add tasks.json * Change xdebug port to 9000
1 parent 23fac9d commit ddb78f0

File tree

5 files changed

+32
-7
lines changed

5 files changed

+32
-7
lines changed

.vscode/launch.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@
88
"name": "Listen for Xdebug (remote/docker)",
99
"type": "php",
1010
"request": "launch",
11+
"hostname": "0.0.0.0",
1112
"port": 9000,
1213
"pathMappings": {
1314
"/var/www/html/": "${workspaceFolder}/docker/wordpress",
1415
"/var/www/html/wp-content/plugins/woocommerce-gateway-stripe/": "${workspaceFolder}"
15-
}
16+
},
17+
"preLaunchTask": "enable:xdebug",
18+
"postDebugTask": "disable:xdebug"
1619
},
1720
{
1821
"name": "Listen for Xdebug (local)",

.vscode/tasks.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
// See https://go.microsoft.com/fwlink/?LinkId=733558
3+
// for the documentation about the tasks.json format
4+
"version": "2.0.0",
5+
"tasks": [
6+
{
7+
"type": "shell",
8+
"command": "npm run xdebug:start",
9+
"label": "enable:xdebug"
10+
},
11+
{
12+
"type": "shell",
13+
"command": "npm run xdebug:stop",
14+
"label": "disable:xdebug"
15+
}
16+
]
17+
}

docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ services:
2121
- ./tests/phpunit:/var/www/html/wp-content/plugins/woocommerce-gateway-stripe/tests/phpunit
2222
- ./docker/dev-php.ini:/usr/local/etc/php/conf.d/dev-php.ini
2323
- ./docker/bin:/var/scripts
24+
extra_hosts:
25+
- "host.docker.internal:host-gateway"
2426
db:
2527
container_name: woocommerce_stripe_mysql
2628
image: mariadb:10.5.8

docker/wordpress_xdebug/Dockerfile

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
FROM wordpress:php7.3
2-
RUN pecl install xdebug-2.9.8 \
3-
&& echo 'xdebug.default_enable=1' >> $PHP_INI_DIR/php.ini \
4-
&& echo 'xdebug.remote_enable=1' >> $PHP_INI_DIR/php.ini \
5-
&& echo 'xdebug.remote_port=9000' >> $PHP_INI_DIR/php.ini \
6-
&& echo 'xdebug.remote_host=host.docker.internal' >> $PHP_INI_DIR/php.ini \
7-
&& echo 'xdebug.remote_autostart=1' >> $PHP_INI_DIR/php.ini \
2+
RUN pecl install xdebug \
3+
&& echo 'xdebug.mode=off' >> $PHP_INI_DIR/php.ini \
4+
&& echo 'xdebug.start_with_request=yes' >> $PHP_INI_DIR/php.ini \
5+
&& echo 'xdebug.client_host=host.docker.internal' >> $PHP_INI_DIR/php.ini \
6+
&& echo 'xdebug.discover_client_host=1' >> $PHP_INI_DIR/php.ini \
7+
&& echo 'xdebug.client_port=9000' >> $PHP_INI_DIR/php.ini \
8+
&& echo 'xdebug.log=/tmp/xdebug.log' >> $PHP_INI_DIR/php.ini \
89
&& docker-php-ext-enable xdebug
910
RUN apt-get update \
1011
&& apt-get install --assume-yes --quiet --no-install-recommends gnupg2 subversion mariadb-client less jq

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@
116116
"uglify": "for f in $npm_package_assets_js_js; do file=${f%.js}; node_modules/.bin/uglifyjs $f -c -m > $file.min.js; done",
117117
"up": "docker-compose up --build --force-recreate -d && ./bin/docker-setup.sh",
118118
"down": "docker-compose down",
119+
"xdebug:start": "docker-compose exec wordpress sh -c 'sed -i \"/xdebug.mode=off/c\\xdebug.mode=debug\" /usr/local/etc/php/php.ini && /etc/init.d/apache2 reload'",
120+
"xdebug:stop": "docker-compose exec wordpress sh -c 'sed -i \"/xdebug.mode=debug/c\\xdebug.mode=off\" /usr/local/etc/php/php.ini && /etc/init.d/apache2 reload",
119121
"wp": "docker run -it --env-file default.env --rm --user xfs --volumes-from woocommerce_stripe_wordpress --network container:woocommerce_stripe_wordpress wordpress:cli",
120122
"listen": "stripe listen --forward-to 'http://localhost:8082/?wc-api=wc_stripe'",
121123
"presass": "rm -f $npm_package_assets_styles_css",

0 commit comments

Comments
 (0)