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.

84 lines
2.1 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. #! /bin/bash
  2. # NOTE: At the moment, this has only been confirmed to work with PHP 7
  3. PHP_VERSION=$2 # Without dot
  4. WITH_PROFILER=$3
  5. # Grab full name of php-fpm container
  6. PHP_FPM_CONTAINER=$(docker ps | grep php${PHP_VERSION} | awk '{print $1}')
  7. if [[ -z "${PHP_FPM_CONTAINER}" ]]; then
  8. echo "Unable to find php fpm container: php${PHP_VERSION}"
  9. exit 1
  10. fi
  11. if [[ ! -z "${WITH_PROFILER}" ]]; then
  12. echo "With profiler option".
  13. fi
  14. xdebug_status ()
  15. {
  16. echo 'xDebug status'
  17. docker exec -it $PHP_FPM_CONTAINER bash -c 'php -v'
  18. }
  19. xdebug_start ()
  20. {
  21. echo 'Start xDebug3'
  22. # And uncomment line with xdebug extension, thus enabling it
  23. ON_CMD="sed -i 's/^;zend_extension=/zend_extension=/g' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini"
  24. if [[ -n "${WITH_PROFILER}" ]]; then
  25. XDEBUG_MODE='profile'
  26. else
  27. XDEBUG_MODE='debug'
  28. fi
  29. MODE_DEBUG_CMD="sed -i 's/^xdebug.mode.*/xdebug.mode=${XDEBUG_MODE}/g' /usr/local/etc/php/conf.d/xdebug.ini"
  30. docker exec -it $PHP_FPM_CONTAINER bash -c "${ON_CMD}"
  31. docker exec -it $PHP_FPM_CONTAINER bash -c "${MODE_DEBUG_CMD}"
  32. docker restart $PHP_FPM_CONTAINER
  33. docker exec -it $PHP_FPM_CONTAINER bash -c 'php -v'
  34. }
  35. xdebug_stop ()
  36. {
  37. echo 'Stop xDebug3'
  38. # Comment out xdebug extension line
  39. OFF_CMD="sed -i 's/^zend_extension=/;zend_extension=/g' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini"
  40. MODE_OFF_CMD="sed -i 's/^xdebug.mode.*/xdebug.mode=off/g' /usr/local/etc/php/conf.d/xdebug.ini"
  41. docker exec -it $PHP_FPM_CONTAINER bash -c "${OFF_CMD}"
  42. docker exec -it $PHP_FPM_CONTAINER bash -c "${MODE_OFF_CMD}"
  43. # docker-compose restart php-fpm
  44. docker restart $PHP_FPM_CONTAINER
  45. docker exec -it $PHP_FPM_CONTAINER bash -c 'php -v'
  46. }
  47. case $1 in
  48. stop|STOP)
  49. xdebug_stop
  50. ;;
  51. start|START)
  52. xdebug_start
  53. ;;
  54. status|STATUS)
  55. xdebug_status
  56. ;;
  57. *)
  58. echo "xDebug [Stop | Start | Status] in the ${PHP_FPM_CONTAINER} container."
  59. echo "xDebug must have already been installed."
  60. echo "Usage:"
  61. echo " .php-fpm/xdebug.sh 73|74 stop|start|status"
  62. esac
  63. exit 1