Skip to content

Commit 1781a53

Browse files
committed
feat: xdebug-set-mode
1 parent 7f212b0 commit 1781a53

File tree

3 files changed

+51
-17
lines changed

3 files changed

+51
-17
lines changed

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,9 @@ RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin/
8383
COPY configs/ports.conf /etc/apache2/ports.conf
8484
COPY configs/logs.conf /etc/apache2/conf-enabled/logs.conf
8585
COPY apache-run.sh /usr/bin/apache-run
86+
COPY ./bin /usr/bin/
8687

87-
RUN chmod a+x /usr/bin/apache-run
88+
RUN chmod a+x /usr/bin/apache-run /usr/bin/xdebug-set-mode
8889

8990
USER www-data
9091

apache-run.sh

100644100755
Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,7 @@
11
#!/bin/bash
22

33
if [[ ${XDEBUG_ENABLED} == true ]]; then
4-
sudo rm -f /usr/local/etc/php/conf.d/xdebug.ini || true
5-
echo "zend_extension=xdebug.so" | sudo tee -a /usr/local/etc/php/conf.d/xdebug.ini
6-
echo "xdebug.var_display_max_depth=5" | sudo tee -a /usr/local/etc/php/conf.d/xdebug.ini
7-
echo "xdebug.idekey=${XDEBUG_IDEKEY}" | sudo tee -a /usr/local/etc/php/conf.d/xdebug.ini
8-
echo "xdebug.mode=debug" | sudo tee -a /usr/local/etc/php/conf.d/xdebug.ini
9-
echo "xdebug.client_port=${XDEBUG_REMOTE_PORT:-$XDEBUG_CLIENT_PORT}" | sudo tee -a /usr/local/etc/php/conf.d/xdebug.ini
10-
11-
export XDEBUG_AUTOSTART=${XDEBUG_AUTOSTART:-$XDEBUG_START_WITH_REQUEST}
12-
[[ ${XDEBUG_AUTOSTART} == true ]] && {
13-
echo "xdebug.start_with_request=yes" | sudo tee -a /usr/local/etc/php/conf.d/xdebug.ini
14-
} || echo "xdebug.start_with_request=no" | sudo tee -a /usr/local/etc/php/conf.d/xdebug.ini
15-
16-
export XDEBUG_CONNECT_BACK=${XDEBUG_CONNECT_BACK:-$XDEBUG_DISCOVER_CLIENT_HOST}
17-
[[ ${XDEBUG_CONNECT_BACK} == true ]] && {
18-
echo "xdebug.discover_client_host=1" | sudo tee -a /usr/local/etc/php/conf.d/xdebug.ini
19-
} || echo "xdebug.discover_client_host=0" | sudo tee -a /usr/local/etc/php/conf.d/xdebug.ini
4+
sudo xdebug-set-mode ${XDEBUG_MODE:-debug}
205
fi
216

227
if [[ ${NR_ENABLED} == true ]]; then

bin/xdebug-set-mode

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env bash
2+
3+
set -o errexit
4+
set -o nounset
5+
set -o pipefail
6+
if [[ "${TRACE-0}" == "1" ]]; then
7+
set -o xtrace
8+
fi
9+
10+
if [[ "${1-}" =~ ^-*h(elp)?$ ]]; then
11+
echo "Usage: $0 [mode]
12+
13+
This script will change PHP INI files to enable the mode set in the argument,
14+
if no argument is set it will fallback to \$XDEBUG_MODE env.
15+
16+
If the mode is 'debug' you will need to set the following env vars:
17+
- XDEBUG_IDEKEY
18+
- XDEBUG_CLIENT_PORT
19+
- XDEBUG_AUTOSTART (optional)
20+
- XDEBUG_CONNECT_BACK (optional)
21+
"
22+
exit
23+
fi
24+
25+
export ini_file=/usr/local/etc/php/conf.d/xdebug.ini
26+
export MODE=${1:-off}
27+
rm -f $ini_file || true
28+
29+
[[ $MODE == "off" ]] && exit
30+
31+
echo "zend_extension=xdebug.so" | tee -a $ini_file
32+
echo "xdebug.mode=$MODE" | tee -a $ini_file
33+
echo "xdebug.var_display_max_depth=5" | tee -a $ini_file
34+
35+
[[ $MODE =~ "debug" ]] && {
36+
echo "xdebug.idekey=${XDEBUG_IDEKEY}" | tee -a $ini_file
37+
38+
client_port=${XDEBUG_REMOTE_PORT:-${XDEBUG_CLIENT_PORT:-9003}}
39+
echo "xdebug.client_port=$client_port" | tee -a $ini_file
40+
41+
autostart="no"
42+
[[ ${XDEBUG_AUTOSTART} == true ]] && autostart="yes"
43+
echo "xdebug.start_with_request=$autostart" | tee -a $ini_file
44+
45+
back="0"
46+
[[ ${XDEBUG_CONNECT_BACK} == true ]] && back="1"
47+
echo "xdebug.discover_client_host=$back" | tee -a $ini_file
48+
}

0 commit comments

Comments
 (0)