To use this script to start a debug session on a CLI script: php-debug vendor/bin/behat features/attribution.feature:555
.
-
-
Save AlucardleVash/a3de30240369cb1e62c31548be55ce02 to your computer and use it in GitHub Desktop.
A little script to easily start a debug session on PHP CLI scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM fpm-prod AS fpm-dev | |
USER 0 | |
# net-tools is used by the php-debug script to get the IP address of the host | |
# system. | |
RUN apt-get update && \ | |
apt-get install -y --no-install-recommends net-tools && \ | |
pecl install xdebug && \ | |
docker-php-ext-enable xdebug && \ | |
rm -rf /var/lib/apt/lists/* /tmp/pear | |
COPY docker/php-debug /usr/local/bin/php-debug | |
USER 1000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -o nounset | |
set -o errexit | |
set -o pipefail | |
[[ "${DEBUG:-}" != "" ]] && set -o xtrace | |
# Find the default gateway (it points to the host system on Linux and probably | |
# on WSL2, but probably not on MacOS). | |
source_ip=$(route | grep default | awk '{print $2}') | |
# PHP_IDE_CONFIG is used by PHPStorm (and presumably other IDEs) to know which | |
# PHP server is triggering a debug session and thus to known which paths mapping | |
# it should use. A default value is defined here but this could be customized | |
# through the .env file at the root of the project. | |
export PHP_IDE_CONFIG=${PHP_IDE_CONFIG:-cadi-fpm} | |
php -d display_errors=on \ | |
-d xdebug.remote_autostart=on \ | |
-d "xdebug.remote_host=${source_ip}" \ | |
${@} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment