Files
structure/dockerfiles/php-fpm/xdebug3/xdebug.sh

85 lines
2.1 KiB
Bash
Raw Normal View History

2020-02-20 22:56:41 +03:00
#! /bin/bash
# NOTE: At the moment, this has only been confirmed to work with PHP 7
PHP_VERSION=$2 # Without dot
WITH_PROFILER=$3
2020-02-20 22:56:41 +03:00
# Grab full name of php-fpm container
PHP_FPM_CONTAINER=$(docker ps | grep php${PHP_VERSION} | awk '{print $1}')
2020-02-20 22:56:41 +03:00
if [[ -z "${PHP_FPM_CONTAINER}" ]]; then
echo "Unable to find php fpm container: php${PHP_VERSION}"
exit 1
fi
2020-02-20 22:56:41 +03:00
if [[ ! -z "${WITH_PROFILER}" ]]; then
echo "With profiler option".
fi
2020-02-20 22:56:41 +03:00
xdebug_status ()
{
echo 'xDebug status'
2021-10-11 18:00:50 +03:00
docker exec -it $PHP_FPM_CONTAINER bash -c 'php -v'
2020-02-20 22:56:41 +03:00
}
xdebug_start ()
{
echo 'Start xDebug3'
2020-02-20 22:56:41 +03:00
# And uncomment line with xdebug extension, thus enabling it
ON_CMD="sed -i 's/^;zend_extension=/zend_extension=/g' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini"
if [[ -n "${WITH_PROFILER}" ]]; then
XDEBUG_MODE='profile'
else
XDEBUG_MODE='debug'
fi
MODE_DEBUG_CMD="sed -i 's/^xdebug.mode.*/xdebug.mode=${XDEBUG_MODE}/g' /usr/local/etc/php/conf.d/xdebug.ini"
2020-02-20 22:56:41 +03:00
2021-10-11 18:00:50 +03:00
docker exec -it $PHP_FPM_CONTAINER bash -c "${ON_CMD}"
2022-11-24 18:27:36 +03:00
docker exec -it $PHP_FPM_CONTAINER bash -c "${MODE_DEBUG_CMD}"
docker restart $PHP_FPM_CONTAINER
docker exec -it $PHP_FPM_CONTAINER bash -c 'php -v'
2020-02-20 22:56:41 +03:00
}
xdebug_stop ()
{
echo 'Stop xDebug3'
2020-02-20 22:56:41 +03:00
# Comment out xdebug extension line
OFF_CMD="sed -i 's/^zend_extension=/;zend_extension=/g' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini"
2022-11-24 18:27:36 +03:00
MODE_OFF_CMD="sed -i 's/^xdebug.mode.*/xdebug.mode=off/g' /usr/local/etc/php/conf.d/xdebug.ini"
2020-02-20 22:56:41 +03:00
2021-10-11 18:02:50 +03:00
docker exec -it $PHP_FPM_CONTAINER bash -c "${OFF_CMD}"
2022-11-24 18:27:36 +03:00
docker exec -it $PHP_FPM_CONTAINER bash -c "${MODE_OFF_CMD}"
2021-10-11 18:02:50 +03:00
# docker-compose restart php-fpm
docker restart $PHP_FPM_CONTAINER
docker exec -it $PHP_FPM_CONTAINER bash -c 'php -v'
2020-02-20 22:56:41 +03:00
}
case $1 in
2020-02-20 22:56:41 +03:00
stop|STOP)
xdebug_stop
;;
start|START)
xdebug_start
;;
status|STATUS)
xdebug_status
;;
*)
echo "xDebug [Stop | Start | Status] in the ${PHP_FPM_CONTAINER} container."
echo "xDebug must have already been installed."
echo "Usage:"
echo " .php-fpm/xdebug.sh 73|74 stop|start|status"
2020-02-20 22:56:41 +03:00
esac
exit 1