zendopcache.sh 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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_ZendOPcache() {
  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}" =~ ^5.[3-4]$ ]]; then
  17. tar xzf zendopcache-${zendopcache_ver}.tgz
  18. pushd zendopcache-${zendopcache_ver} > /dev/null
  19. else
  20. src_url=https://secure.php.net/distributions/php-${PHP_detail_ver}.tar.gz && Download_src
  21. tar xzf php-${PHP_detail_ver}.tar.gz
  22. pushd php-${PHP_detail_ver}/ext/opcache > /dev/null
  23. fi
  24. ${php_install_dir}/bin/phpize
  25. ./configure --with-php-config=${php_install_dir}/bin/php-config
  26. make -j ${THREAD} && make install
  27. popd > /dev/null
  28. if [ -f "${phpExtensionDir}/opcache.so" ]; then
  29. # write opcache configs
  30. if [[ "${PHP_main_ver}" =~ ^5.[3-4]$ ]]; then
  31. # For php 5.3 5.4
  32. cat > ${php_install_dir}/etc/php.d/02-opcache.ini << EOF
  33. [opcache]
  34. zend_extension=${phpExtensionDir}/opcache.so
  35. opcache.enable=1
  36. opcache.memory_consumption=${Memory_limit}
  37. opcache.interned_strings_buffer=8
  38. opcache.max_accelerated_files=4000
  39. opcache.revalidate_freq=60
  40. ;opcache.save_comments=0
  41. opcache.fast_shutdown=1
  42. opcache.enable_cli=1
  43. ;opcache.optimization_level=0
  44. EOF
  45. rm -rf zendopcache-${zendopcache_ver}
  46. else
  47. # For php 5.5+
  48. cat > ${php_install_dir}/etc/php.d/02-opcache.ini << EOF
  49. [opcache]
  50. zend_extension=opcache.so
  51. opcache.enable=1
  52. opcache.enable_cli=1
  53. opcache.memory_consumption=${Memory_limit}
  54. opcache.interned_strings_buffer=8
  55. opcache.max_accelerated_files=100000
  56. opcache.max_wasted_percentage=5
  57. opcache.use_cwd=1
  58. opcache.validate_timestamps=1
  59. opcache.revalidate_freq=60
  60. ;opcache.save_comments=0
  61. opcache.fast_shutdown=1
  62. opcache.consistency_checks=0
  63. ;opcache.optimization_level=0
  64. EOF
  65. fi
  66. echo "${CSUCCESS}PHP opcache module installed successfully! ${CEND}"
  67. rm -rf php-${PHP_detail_ver}
  68. else
  69. echo "${CFAILURE}PHP opcache module install failed, Please contact the author! ${CEND}" && grep -Ew 'NAME|ID|ID_LIKE|VERSION_ID|PRETTY_NAME' /etc/os-release
  70. fi
  71. popd > /dev/null
  72. fi
  73. }
  74. Uninstall_ZendOPcache() {
  75. if [ -e "${php_install_dir}/etc/php.d/02-opcache.ini" ]; then
  76. rm -f ${php_install_dir}/etc/php.d/02-opcache.ini
  77. echo; echo "${CMSG}PHP opcache module uninstall completed${CEND}"
  78. else
  79. echo; echo "${CWARNING}PHP opcache module does not exist! ${CEND}"
  80. fi
  81. }