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.

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