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.

102 lines
2.6 KiB

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