pecl_xdebug.sh 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/bin/bash
  2. # Author: yeho <lj2007331 AT gmail.com>
  3. # BLOG: https://linuxeye.com
  4. #
  5. # Notes: OneinStack for CentOS/RedHat 7+ Debian 9+ and Ubuntu 16+
  6. #
  7. # Project home page:
  8. # https://oneinstack.com
  9. # https://github.com/oneinstack/oneinstack
  10. Install_pecl_xdebug() {
  11. if [ -e "${php_install_dir}/bin/phpize" ]; then
  12. pushd ${oneinstack_dir}/src > /dev/null
  13. phpExtensionDir=$(${php_install_dir}/bin/php-config --extension-dir)
  14. PHP_detail_ver=$(${php_install_dir}/bin/php-config --version)
  15. PHP_main_ver=${PHP_detail_ver%.*}
  16. if [[ "${PHP_main_ver}" =~ ^7.[0-4]$|^80$ ]]; then
  17. if [[ "${PHP_main_ver}" =~ ^7.[0-1]$ ]]; then
  18. src_url=https://pecl.php.net/get/xdebug-${xdebug_oldver}.tgz && Download_src
  19. tar xzf xdebug-${xdebug_oldver}.tgz
  20. pushd xdebug-${xdebug_oldver} > /dev/null
  21. else
  22. src_url=https://pecl.php.net/get/xdebug-${xdebug_ver}.tgz && Download_src
  23. tar xzf xdebug-${xdebug_ver}.tgz
  24. pushd xdebug-${xdebug_ver} > /dev/null
  25. fi
  26. ${php_install_dir}/bin/phpize
  27. ./configure --with-php-config=${php_install_dir}/bin/php-config
  28. make -j ${THREAD} && make install
  29. popd > /dev/null
  30. if [ -f "${phpExtensionDir}/xdebug.so" ]; then
  31. src_url=${mirror_link}/oneinstack/src/webgrind-master.zip && Download_src
  32. unzip -q webgrind-master.zip
  33. /bin/mv webgrind-master ${wwwroot_dir}/default/webgrind
  34. [ ! -e /tmp/xdebug ] && { mkdir /tmp/xdebug; chown ${run_user}:${run_group} /tmp/xdebug; }
  35. [ ! -e /tmp/webgrind ] && { mkdir /tmp/webgrind; chown ${run_user}:${run_group} /tmp/webgrind; }
  36. chown -R ${run_user}:${run_group} ${wwwroot_dir}/default/webgrind
  37. sed -i 's@static $storageDir.*@static $storageDir = "/tmp/webgrind";@' ${wwwroot_dir}/default/webgrind/config.php
  38. sed -i 's@static $profilerDir.*@static $profilerDir = "/tmp/xdebug";@' ${wwwroot_dir}/default/webgrind/config.php
  39. cat > ${php_install_dir}/etc/php.d/08-xdebug.ini << EOF
  40. [xdebug]
  41. zend_extension=xdebug.so
  42. xdebug.trace_output_dir=/tmp/xdebug
  43. xdebug.profiler_output_dir = /tmp/xdebug
  44. xdebug.profiler_enable = On
  45. xdebug.profiler_enable_trigger = 1
  46. EOF
  47. echo "${CSUCCESS}PHP xdebug module installed successfully! ${CEND}"
  48. echo; echo "Webgrind URL: ${CMSG}http://{Public IP}/webgrind ${CEND}"
  49. rm -rf xdebug-${xdebug_ver} xdebug-${xdebug_oldver}
  50. else
  51. echo "${CFAILURE}PHP xdebug module install failed, Please contact the author! ${CEND}" && grep -Ew 'NAME|ID|ID_LIKE|VERSION_ID|PRETTY_NAME' /etc/os-release
  52. fi
  53. else
  54. echo "${CWARNING}Your php ${PHP_detail_ver} does not support xdebug! ${CEND}";
  55. fi
  56. popd > /dev/null
  57. fi
  58. }
  59. Uninstall_pecl_xdebug() {
  60. if [ -e "${php_install_dir}/etc/php.d/08-xdebug.ini" ]; then
  61. rm -rf ${php_install_dir}/etc/php.d/08-xdebug.ini /tmp/{xdebug,webgrind} ${wwwroot_dir}/default/webgrind
  62. echo; echo "${CMSG}PHP xdebug module uninstall completed${CEND}"
  63. else
  64. echo; echo "${CWARNING}PHP xdebug module does not exist! ${CEND}"
  65. fi
  66. }