You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
2.1 KiB

  1. #!/bin/bash
  2. # Line above doe not correctly work for this script symlinks
  3. #SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
  4. # And symlinks are not working on windows.
  5. SCRIPT_DIR="$(realpath $(dirname "$(readlink -f "$0")"))"
  6. set -e
  7. . $SCRIPT_DIR/_helpers.sh || {
  8. echo "no helpers" && exit 1
  9. }
  10. cd "$SCRIPT_DIR/.."
  11. PHP_VERSION=$1
  12. if [[ -z "${PHP_VERSION}" ]]; then PHP_VERSION=81; fi
  13. WITH_PROFILER=$2
  14. PHP_DOT_VERSION=$(dot_version ${PHP_VERSION})
  15. PHP_FPM_CONTAINER=$(docker ps | grep "php${PHP_VERSION}" | awk '{print $1}')
  16. WORKSPACE_CONTAINER=$(docker ps | grep "workspace${PHP_VERSION}" | awk '{print $1}')
  17. PHP_FPM_XDEBUG_EXT_PATH=/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
  18. WORKSPACE_XDEBUG_EXT_PATH=/etc/php/${PHP_DOT_VERSION}/cli/conf.d/20-xdebug.ini
  19. PHP_FPM_XDEBUG_CONFIG_PATH=/usr/local/etc/php/conf.d/xdebug.ini
  20. WORKSPACE_XDEBUG_CONFIG_PATH=/etc/php/${PHP_DOT_VERSION}/cli/conf.d/xdebug.ini
  21. SED_XDEBUG_ON="sed -i 's/^;zend_extension=/zend_extension=/g'"
  22. docker exec -it "${PHP_FPM_CONTAINER}" bash -c "${SED_XDEBUG_ON} ${PHP_FPM_XDEBUG_EXT_PATH}"
  23. docker exec -it "${WORKSPACE_CONTAINER}" bash -c "${SED_XDEBUG_ON} ${WORKSPACE_XDEBUG_EXT_PATH}"
  24. echo "Turn on xdebug: $PHP_VERSION"
  25. if [ -n "${WITH_PROFILER}" ]; then
  26. echo "Profiler enabled"
  27. if [ "${PHP_VERSION}" = 74 ]; then
  28. SED_DEBUG_OR_PROFILER_MODE_ON="sed -i 's/^xdebug.profiler_enable=.*/xdebug.profiler_enable=1/g'"
  29. else
  30. SED_DEBUG_OR_PROFILER_MODE_ON="sed -i 's/^xdebug.mode=.*/xdebug.mode=profile/g'"
  31. fi
  32. elif [ "${PHP_VERSION}" -ne 74 ]; then
  33. SED_DEBUG_OR_PROFILER_MODE_ON="sed -i 's/^xdebug.mode=.*/xdebug.mode=debug/g'"
  34. fi
  35. if [ -n "${SED_DEBUG_OR_PROFILER_MODE_ON}" ]; then
  36. docker exec -it "${PHP_FPM_CONTAINER}" bash -c "${SED_DEBUG_OR_PROFILER_MODE_ON} ${PHP_FPM_XDEBUG_CONFIG_PATH}"
  37. docker exec -it "${WORKSPACE_CONTAINER}" bash -c "${SED_DEBUG_OR_PROFILER_MODE_ON} ${WORKSPACE_XDEBUG_CONFIG_PATH}"
  38. fi
  39. docker restart "${PHP_FPM_CONTAINER}"
  40. echo 'Use this for resolve hostname in your IDE debugger:'
  41. echo 'export PHP_IDE_CONFIG="serverName=myproject.cli.local.wpstudio.ru"'