pecl_mongodb.sh 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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_mongodb() {
  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. if [[ "$(${php_install_dir}/bin/php-config --version | awk -F. '{print $1$2}')" =~ ^5[3-4]$ ]]; then
  15. src_url=https://pecl.php.net/get/mongo-${pecl_mongo_ver}.tgz && Download_src
  16. tar xzf mongo-${pecl_mongo_ver}.tgz
  17. pushd mongo-${pecl_mongo_ver} > /dev/null
  18. ${php_install_dir}/bin/phpize
  19. ./configure --with-php-config=${php_install_dir}/bin/php-config
  20. make -j ${THREAD} && make install
  21. popd > /dev/null
  22. if [ -f "${phpExtensionDir}/mongo.so" ]; then
  23. echo 'extension=mongo.so' > ${php_install_dir}/etc/php.d/07-mongo.ini
  24. rm -rf mongo-${pecl_mongo_ver}
  25. echo "${CSUCCESS}PHP mongo module installed successfully! ${CEND}"
  26. else
  27. echo "${CFAILURE}PHP mongo module install failed, Please contact the author! ${CEND}" && grep -Ew 'NAME|ID|ID_LIKE|VERSION_ID|PRETTY_NAME' /etc/os-release
  28. fi
  29. else
  30. if [[ "$(${php_install_dir}/bin/php-config --version | awk -F. '{print $1$2}')" =~ ^7[0-2]$ ]]; then
  31. src_url=https://pecl.php.net/get/mongodb-${pecl_mongodb_oldver}.tgz && Download_src
  32. tar xzf mongodb-${pecl_mongodb_oldver}.tgz
  33. pushd mongodb-${pecl_mongodb_oldver} > /dev/null
  34. else
  35. src_url=https://pecl.php.net/get/mongodb-${pecl_mongodb_ver}.tgz && Download_src
  36. tar xzf mongodb-${pecl_mongodb_ver}.tgz
  37. pushd mongodb-${pecl_mongodb_ver} > /dev/null
  38. fi
  39. ${php_install_dir}/bin/phpize
  40. ./configure --with-php-config=${php_install_dir}/bin/php-config
  41. make -j ${THREAD} && make install
  42. popd > /dev/null
  43. if [ -f "${phpExtensionDir}/mongodb.so" ]; then
  44. echo 'extension=mongodb.so' > ${php_install_dir}/etc/php.d/07-mongodb.ini
  45. echo "${CSUCCESS}PHP mongodb module installed successfully! ${CEND}"
  46. rm -rf mongodb-${pecl_mongodb_oldver} mongodb-${pecl_mongodb_ver}
  47. else
  48. echo "${CFAILURE}PHP mongodb module install failed, Please contact the author! ${CEND}" && grep -Ew 'NAME|ID|ID_LIKE|VERSION_ID|PRETTY_NAME' /etc/os-release
  49. fi
  50. fi
  51. popd > /dev/null
  52. fi
  53. }
  54. Uninstall_pecl_mongodb() {
  55. if [ -e "${php_install_dir}/etc/php.d/07-mongo.ini" ]; then
  56. rm -f ${php_install_dir}/etc/php.d/07-mongo.ini
  57. echo; echo "${CMSG}PHP mongo module uninstall completed${CEND}"
  58. else
  59. echo; echo "${CWARNING}PHP mongo module does not exist! ${CEND}"
  60. fi
  61. if [ -e "${php_install_dir}/etc/php.d/07-mongodb.ini" ]; then
  62. rm -f ${php_install_dir}/etc/php.d/07-mongodb.ini
  63. echo; echo "${CMSG}PHP mongodb module uninstall completed${CEND}"
  64. else
  65. echo; echo "${CWARNING}PHP mongodb module does not exist! ${CEND}"
  66. fi
  67. }