zendopcache.sh 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/bin/bash
  2. # Author: yeho <lj2007331 AT gmail.com>
  3. # BLOG: https://blog.linuxeye.cn
  4. #
  5. # Notes: OneinStack for CentOS/RadHat 6+ Debian 6+ and Ubuntu 12+
  6. #
  7. # Project home page:
  8. # https://oneinstack.com
  9. # https://github.com/lj2007331/oneinstack
  10. Install_ZendOPcache() {
  11. pushd ${oneinstack_dir}/src > /dev/null
  12. phpExtensionDir=$(${php_install_dir}/bin/php-config --extension-dir)
  13. PHP_detail_ver=$(${php_install_dir}/bin/php -r 'echo PHP_VERSION;')
  14. PHP_main_ver=${PHP_detail_ver%.*}
  15. if [[ "${PHP_main_ver}" =~ ^5.[3-4]$ ]]; then
  16. tar xzf zendopcache-${zendopcache_ver}.tgz
  17. pushd zendopcache-${zendopcache_ver}
  18. else
  19. tar xzf php-${PHP_detail_ver}.tar.gz
  20. pushd php-${PHP_detail_ver}/ext/opcache
  21. fi
  22. ${php_install_dir}/bin/phpize
  23. ./configure --with-php-config=${php_install_dir}/bin/php-config
  24. make -j ${THREAD} && make install
  25. popd
  26. if [ -f "${phpExtensionDir}/opcache.so" ]; then
  27. # write opcache configs
  28. if [[ "${PHP_main_ver}" =~ ^5.[3-4]$ ]]; then
  29. # For php 5.3 5.4
  30. cat > ${php_install_dir}/etc/php.d/02-opcache.ini << EOF
  31. [opcache]
  32. zend_extension=${phpExtensionDir}/opcache.so
  33. opcache.enable=1
  34. opcache.memory_consumption=${Memory_limit}
  35. opcache.interned_strings_buffer=8
  36. opcache.max_accelerated_files=4000
  37. opcache.revalidate_freq=60
  38. opcache.save_comments=0
  39. opcache.fast_shutdown=1
  40. opcache.enable_cli=1
  41. ;opcache.optimization_level=0
  42. EOF
  43. else
  44. # For php 5.5+
  45. cat > ${php_install_dir}/etc/php.d/02-opcache.ini << EOF
  46. [opcache]
  47. zend_extension=opcache.so
  48. opcache.enable=1
  49. opcache.enable_cli=1
  50. opcache.memory_consumption=${Memory_limit}
  51. opcache.interned_strings_buffer=8
  52. opcache.max_accelerated_files=100000
  53. opcache.max_wasted_percentage=5
  54. opcache.use_cwd=1
  55. opcache.validate_timestamps=1
  56. opcache.revalidate_freq=60
  57. opcache.save_comments=0
  58. opcache.fast_shutdown=1
  59. opcache.consistency_checks=0
  60. ;opcache.optimization_level=0
  61. EOF
  62. fi
  63. echo "${CSUCCESS}PHP OPcache module installed successfully! ${CEND}"
  64. rm -rf zendopcache-${zendopcache_ver} php-${PHP_detail_ver}
  65. else
  66. echo "${CFAILURE}PHP OPcache module install failed, Please contact the author! ${CEND}"
  67. fi
  68. popd
  69. }