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.

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