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.

87 lines
2.9 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
  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. REMOTE_AUTOSTART_CMD="sed -i 's/^xdebug.remote_autostart=0/xdebug.remote_autostart=1/g' /usr/local/etc/php/conf.d/xdebug.ini"
  25. REMOTE_ENABLE_CMD="sed -i 's/^xdebug.remote_enable=0/xdebug.remote_enable=1/g' /usr/local/etc/php/conf.d/xdebug.ini"
  26. PROFILER_ENABLE_CDM="sed -i 's/^xdebug.profiler_enable=0/xdebug.profiler_enable=1/g' /usr/local/etc/php/conf.d/xdebug.ini"
  27. docker exec -it $PHP_FPM_CONTAINER bash -c "${ON_CMD}"
  28. docker exec -it $PHP_FPM_CONTAINER bash -c "${REMOTE_AUTOSTART_CMD}"
  29. docker exec -it $PHP_FPM_CONTAINER bash -c "${REMOTE_ENABLE_CMD}"
  30. if [[ ! -z "${WITH_PROFILER}" ]]; then
  31. docker exec -it $PHP_FPM_CONTAINER bash -c "${PROFILER_ENABLE_CDM}"
  32. fi
  33. docker restart $PHP_FPM_CONTAINER
  34. docker exec -it $PHP_FPM_CONTAINER bash -c 'php -v'
  35. }
  36. xdebug_stop ()
  37. {
  38. echo 'Stop xDebug'
  39. # Comment out xdebug extension line
  40. OFF_CMD="sed -i 's/^zend_extension=/;zend_extension=/g' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini"
  41. REMOTE_AUTOSTART_CMD="sed -i 's/^xdebug.remote_autostart=1/xdebug.remote_autostart=0/g' /usr/local/etc/php/conf.d/xdebug.ini"
  42. REMOTE_ENABLE_CMD="sed -i 's/^xdebug.remote_enable=1/xdebug.remote_enable=0/g' /usr/local/etc/php/conf.d/xdebug.ini"
  43. PROFILER_DISABLE_CMD="sed -i 's/^xdebug.profiler_enable=1/xdebug.profiler_enable=0/g' /usr/local/etc/php/conf.d/xdebug.ini"
  44. docker exec -it $PHP_FPM_CONTAINER bash -c "${OFF_CMD}"
  45. docker exec -it $PHP_FPM_CONTAINER bash -c "${REMOTE_AUTOSTART_CMD}"
  46. docker exec -it $PHP_FPM_CONTAINER bash -c "${REMOTE_ENABLE_CMD}"
  47. docker exec -it $PHP_FPM_CONTAINER bash -c "${PROFILER_DISABLE_CMD}"
  48. # docker-compose restart php-fpm
  49. docker restart $PHP_FPM_CONTAINER
  50. docker exec -it $PHP_FPM_CONTAINER bash -c 'php -v'
  51. }
  52. case $1 in
  53. stop|STOP)
  54. xdebug_stop
  55. ;;
  56. start|START)
  57. xdebug_start
  58. ;;
  59. status|STATUS)
  60. xdebug_status
  61. ;;
  62. *)
  63. echo "xDebug [Stop | Start | Status] in the ${PHP_FPM_CONTAINER} container."
  64. echo "xDebug must have already been installed."
  65. echo "Usage:"
  66. echo " .php-fpm/xdebug.sh 73|74 stop|start|status"
  67. esac
  68. exit 1