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.

77 lines
2.0 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
  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 xDebug'
  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. MODE_DEBUG_CMD="sed -i 's/^xdebug.mode.*/xdebug.mode=debug/g' /usr/local/etc/php/conf.d/xdebug.ini"
  25. docker exec -it $PHP_FPM_CONTAINER bash -c "${ON_CMD}"
  26. docker exec -it $PHP_FPM_CONTAINER bash -c "${MODE_DEBUG_CMD}"
  27. docker restart $PHP_FPM_CONTAINER
  28. docker exec -it $PHP_FPM_CONTAINER bash -c 'php -v'
  29. }
  30. xdebug_stop ()
  31. {
  32. echo 'Stop xDebug'
  33. # Comment out xdebug extension line
  34. OFF_CMD="sed -i 's/^zend_extension=/;zend_extension=/g' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini"
  35. MODE_OFF_CMD="sed -i 's/^xdebug.mode.*/xdebug.mode=off/g' /usr/local/etc/php/conf.d/xdebug.ini"
  36. docker exec -it $PHP_FPM_CONTAINER bash -c "${OFF_CMD}"
  37. docker exec -it $PHP_FPM_CONTAINER bash -c "${MODE_OFF_CMD}"
  38. # docker-compose restart php-fpm
  39. docker restart $PHP_FPM_CONTAINER
  40. docker exec -it $PHP_FPM_CONTAINER bash -c 'php -v'
  41. }
  42. case $1 in
  43. stop|STOP)
  44. xdebug_stop
  45. ;;
  46. start|START)
  47. xdebug_start
  48. ;;
  49. status|STATUS)
  50. xdebug_status
  51. ;;
  52. *)
  53. echo "xDebug [Stop | Start | Status] in the ${PHP_FPM_CONTAINER} container."
  54. echo "xDebug must have already been installed."
  55. echo "Usage:"
  56. echo " .php-fpm/xdebug.sh 73|74 stop|start|status"
  57. esac
  58. exit 1