eaccelerator.sh 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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_eAccelerator() {
  11. if [ -e "${php_install_dir}/bin/phpize" ]; then
  12. pushd ${oneinstack_dir}/src > /dev/null
  13. PHP_detail_ver=$(${php_install_dir}/bin/php-config --version)
  14. PHP_main_ver=${PHP_detail_ver%.*}
  15. phpExtensionDir=$(${php_install_dir}/bin/php-config --extension-dir)
  16. if [[ "${PHP_main_ver}" =~ ^5.[3-4]$ ]]; then
  17. if [ "${PHP_main_ver}" == '5.3' ]; then
  18. tar jxf eaccelerator-${eaccelerator_ver}.tar.bz2
  19. pushd eaccelerator-${eaccelerator_ver} > /dev/null
  20. elif [ "${PHP_main_ver}" == '5.4' ]; then
  21. /bin/mv master eaccelerator-eaccelerator-42067ac.tar.gz
  22. tar xzf eaccelerator-eaccelerator-42067ac.tar.gz
  23. pushd eaccelerator-eaccelerator-42067ac > /dev/null
  24. fi
  25. ${php_install_dir}/bin/phpize
  26. ./configure --enable-eaccelerator=shared --with-php-config=${php_install_dir}/bin/php-config
  27. make -j ${THREAD} && make install
  28. popd > /dev/null
  29. if [ -f "${phpExtensionDir}/eaccelerator.so" ]; then
  30. mkdir /var/eaccelerator_cache;chown -R ${run_user}:${run_group} /var/eaccelerator_cache
  31. cat > ${php_install_dir}/etc/php.d/02-eaccelerator.ini << EOF
  32. [eaccelerator]
  33. zend_extension=${phpExtensionDir}/eaccelerator.so
  34. eaccelerator.shm_size=64
  35. eaccelerator.cache_dir=/var/eaccelerator_cache
  36. eaccelerator.enable=1
  37. eaccelerator.optimizer=1
  38. eaccelerator.check_mtime=1
  39. eaccelerator.debug=0
  40. eaccelerator.filter=
  41. eaccelerator.shm_max=0
  42. eaccelerator.shm_ttl=0
  43. eaccelerator.shm_prune_period=0
  44. eaccelerator.shm_only=0
  45. eaccelerator.compress=0
  46. eaccelerator.compress_level=9
  47. eaccelerator.keys=disk_only
  48. eaccelerator.sessions=disk_only
  49. eaccelerator.content=disk_only
  50. EOF
  51. [ -z "$(grep 'kernel.shmmax = 67108864' /etc/sysctl.conf)" ] && echo "kernel.shmmax = 67108864" >> /etc/sysctl.conf
  52. sysctl -p
  53. echo "${CSUCCESS}PHP eaccelerator module installed successfully! ${CEND}"
  54. rm -rf eaccelerator-${eaccelerator_ver} eaccelerator-eaccelerator-42067ac
  55. else
  56. echo "${CFAILURE}PHP eaccelerator module install failed, Please contact the author! ${CEND}" && grep -Ew 'NAME|ID|ID_LIKE|VERSION_ID|PRETTY_NAME' /etc/os-release
  57. fi
  58. else
  59. echo; echo "${CWARNING}Your php ${PHP_detail_ver} does not support eAccelerator! ${CEND}";
  60. fi
  61. popd > /dev/null
  62. fi
  63. }
  64. Uninstall_eAccelerator() {
  65. if [ -e "${php_install_dir}/etc/php.d/02-eaccelerator.ini" ]; then
  66. rm -rf ${php_install_dir}/etc/php.d/02-eaccelerator.ini /var/eaccelerator_cache
  67. echo; echo "${CMSG}PHP eaccelerator module uninstall completed${CEND}"
  68. else
  69. echo; echo "${CWARNING}PHP eaccelerator module does not exist! ${CEND}"
  70. fi
  71. }