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.

101 lines
2.6 KiB

5 years ago
  1. #! /bin/bash
  2. # NOTE: At the moment, this has only been confirmed to work with PHP 7
  3. # Grab full name of php-fpm container
  4. PHP_FPM_CONTAINER=$(docker ps | grep php-fpm | awk '{print $1}')
  5. # Grab OS type
  6. if [[ "$(uname)" == "Darwin" ]]; then
  7. OS_TYPE="OSX"
  8. else
  9. OS_TYPE=$(expr substr $(uname -s) 1 5)
  10. fi
  11. xdebug_status ()
  12. {
  13. echo 'xDebug status'
  14. # If running on Windows, need to prepend with winpty :(
  15. if [[ $OS_TYPE == "MINGW" ]]; then
  16. winpty docker exec -it $PHP_FPM_CONTAINER bash -c 'php -v'
  17. else
  18. docker exec -it $PHP_FPM_CONTAINER bash -c 'php -v'
  19. fi
  20. }
  21. xdebug_start ()
  22. {
  23. echo 'Start xDebug'
  24. # And uncomment line with xdebug extension, thus enabling it
  25. ON_CMD="sed -i 's/^;zend_extension=/zend_extension=/g' \
  26. /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini"
  27. # If running on Windows, need to prepend with winpty :(
  28. if [[ $OS_TYPE == "MINGW" ]]; then
  29. winpty docker exec -it $PHP_FPM_CONTAINER bash -c "${ON_CMD}"
  30. docker restart $PHP_FPM_CONTAINER
  31. winpty docker exec -it $PHP_FPM_CONTAINER bash -c 'php -v'
  32. else
  33. docker exec -it $PHP_FPM_CONTAINER bash -c "${ON_CMD}"
  34. docker restart $PHP_FPM_CONTAINER
  35. docker exec -it $PHP_FPM_CONTAINER bash -c 'php -v'
  36. fi
  37. }
  38. xdebug_stop ()
  39. {
  40. echo 'Stop xDebug'
  41. # Comment out xdebug extension line
  42. OFF_CMD="sed -i 's/^zend_extension=/;zend_extension=/g' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini"
  43. # If running on Windows, need to prepend with winpty :(
  44. if [[ $OS_TYPE == "MINGW" ]]; then
  45. # This is the equivalent of:
  46. # winpty docker exec -it laradock_php-fpm_1 bash -c 'bla bla bla'
  47. # Thanks to @michaelarnauts at https://github.com/docker/compose/issues/593
  48. winpty docker exec -it $PHP_FPM_CONTAINER bash -c "${OFF_CMD}"
  49. docker restart $PHP_FPM_CONTAINER
  50. #docker-compose restart php-fpm
  51. winpty docker exec -it $PHP_FPM_CONTAINER bash -c 'php -v'
  52. else
  53. docker exec -it $PHP_FPM_CONTAINER bash -c "${OFF_CMD}"
  54. # docker-compose restart php-fpm
  55. docker restart $PHP_FPM_CONTAINER
  56. docker exec -it $PHP_FPM_CONTAINER bash -c 'php -v'
  57. fi
  58. }
  59. case $@ in
  60. stop|STOP)
  61. xdebug_stop
  62. ;;
  63. start|START)
  64. xdebug_start
  65. ;;
  66. status|STATUS)
  67. xdebug_status
  68. ;;
  69. *)
  70. echo "xDebug [Stop | Start | Status] in the ${PHP_FPM_CONTAINER} container."
  71. echo "xDebug must have already been installed."
  72. echo "Usage:"
  73. echo " .php-fpm/xdebug stop|start|status"
  74. esac
  75. exit 1