1
0

addons.sh 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. #!/bin/bash
  2. # Author: yeho <lj2007331 AT gmail.com>
  3. # BLOG: https://blog.linuxeye.com
  4. #
  5. # Notes: OneinStack for CentOS/RadHat 5+ Debian 6+ and Ubuntu 12+
  6. #
  7. # Project home page:
  8. # http://oneinstack.com
  9. # https://github.com/lj2007331/oneinstack
  10. export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
  11. clear
  12. printf "
  13. #######################################################################
  14. # OneinStack for CentOS/RadHat 5+ Debian 6+ and Ubuntu 12+ #
  15. # Install/Uninstall PHP Extensions #
  16. # For more information please visit http://oneinstack.com #
  17. #######################################################################
  18. "
  19. # get pwd
  20. sed -i "s@^oneinstack_dir.*@oneinstack_dir=`pwd`@" ./options.conf
  21. . ./apps.conf
  22. . ./options.conf
  23. . ./include/color.sh
  24. . ./include/memory.sh
  25. . ./include/check_os.sh
  26. . ./include/download.sh
  27. . ./include/get_char.sh
  28. . ./include/zendopcache.sh
  29. . ./include/xcache.sh
  30. . ./include/apcu.sh
  31. . ./include/eaccelerator-0.9.sh
  32. . ./include/eaccelerator-1.0-dev.sh
  33. . ./include/ZendGuardLoader.sh
  34. . ./include/ioncube.sh
  35. . ./include/ImageMagick.sh
  36. . ./include/GraphicsMagick.sh
  37. . ./include/memcached.sh
  38. . ./include/redis.sh
  39. # Check if user is root
  40. [ $(id -u) != "0" ] && { echo "${CFAILURE}Error: You must be root to run this script${CEND}"; exit 1; }
  41. # Check PHP
  42. if [ -e "$php_install_dir/bin/phpize" ];then
  43. PHP_version=`$php_install_dir/bin/php -r 'echo PHP_VERSION;' | awk -F. '{print $1"."$2}'`
  44. else
  45. echo "${CWARNING}PHP is not installed on your system! You can use to uninstall and reinstall PHP Extensions${CEND}"; exit 1
  46. fi
  47. # Check PHP Extensions
  48. Check_PHP_Extension() {
  49. [ -e "$php_install_dir/etc/php.d/ext-${PHP_extension}.ini" ] && { echo "${CWARNING}PHP $PHP_extension module already installed! ${CEND}"; exit 1; }
  50. }
  51. # restart PHP
  52. Restart_PHP() {
  53. [ -e "$apache_install_dir/conf/httpd.conf" ] && /etc/init.d/httpd restart || /etc/init.d/php-fpm restart
  54. }
  55. # Check succ
  56. Check_succ() {
  57. [ -f "`$php_install_dir/bin/php-config --extension-dir`/${PHP_extension}.so" ] && { Restart_PHP; echo;echo "${CSUCCESS}PHP $PHP_extension module install successfully! ${CEND}"; }
  58. }
  59. # Uninstall succ
  60. Uninstall_succ() {
  61. [ -e "$php_install_dir/etc/php.d/ext-${PHP_extension}.ini" ] && { rm -rf $php_install_dir/etc/php.d/ext-${PHP_extension}.ini; Restart_PHP; echo; echo "${CMSG}PHP $PHP_extension module uninstall completed${CEND}"; } || { echo; echo "${CWARNING}$PHP_extension module does not exist! ${CEND}"; }
  62. }
  63. # PHP 5.5,5,6,7.0 install opcache
  64. Install_opcache() {
  65. $php_install_dir/bin/phpize
  66. ./configure --with-php-config=$php_install_dir/bin/php-config
  67. make -j ${THREAD} && make install
  68. cat > $php_install_dir/etc/php.d/ext-opcache.ini << EOF
  69. [opcache]
  70. zend_extension=opcache.so
  71. opcache.enable=1
  72. opcache.memory_consumption=$Memory_limit
  73. opcache.interned_strings_buffer=8
  74. opcache.max_accelerated_files=4000
  75. opcache.revalidate_freq=60
  76. opcache.save_comments=0
  77. opcache.fast_shutdown=1
  78. opcache.enable_cli=1
  79. ;opcache.optimization_level=0
  80. EOF
  81. }
  82. ACTION_FUN() {
  83. while :; do
  84. echo
  85. echo 'Please select an action:'
  86. echo -e "\t${CMSG}1${CEND}. install"
  87. echo -e "\t${CMSG}2${CEND}. uninstall"
  88. read -p "Please input a number:(Default 1 press Enter) " ACTION
  89. [ -z "$ACTION" ] && ACTION=1
  90. if [[ ! $ACTION =~ ^[1,2]$ ]];then
  91. echo "${CWARNING}input error! Please only input number 1,2${CEND}"
  92. else
  93. break
  94. fi
  95. done
  96. }
  97. while :;do
  98. printf "
  99. What Are You Doing?
  100. \t${CMSG}1${CEND}. Install/Uninstall PHP opcode cache
  101. \t${CMSG}2${CEND}. Install/Uninstall ZendGuardLoader/ionCube PHP Extension
  102. \t${CMSG}3${CEND}. Install/Uninstall ImageMagick/GraphicsMagick PHP Extension
  103. \t${CMSG}4${CEND}. Install/Uninstall memcached/memcache
  104. \t${CMSG}5${CEND}. Install/Uninstall Redis
  105. \t${CMSG}q${CEND}. Exit
  106. "
  107. read -p "Please input the correct option: " Number
  108. if [[ ! $Number =~ ^[1-5,q]$ ]];then
  109. echo "${CFAILURE}input error! Please only input 1 ~ 5 and q${CEND}"
  110. else
  111. case "$Number" in
  112. 1)
  113. ACTION_FUN
  114. while :; do echo
  115. echo 'Please select a opcode cache of the PHP:'
  116. echo -e "\t${CMSG}1${CEND}. Zend OPcache"
  117. echo -e "\t${CMSG}2${CEND}. XCache"
  118. echo -e "\t${CMSG}3${CEND}. APCU"
  119. echo -e "\t${CMSG}4${CEND}. eAccelerator"
  120. read -p "Please input a number:(Default 1 press Enter) " PHP_cache
  121. [ -z "$PHP_cache" ] && PHP_cache=1
  122. if [[ ! $PHP_cache =~ ^[1-4]$ ]];then
  123. echo "${CWARNING}input error! Please only input number 1,2,3,4${CEND}"
  124. else
  125. [ $PHP_cache = 1 ] && PHP_extension=opcache
  126. [ $PHP_cache = 2 ] && PHP_extension=xcache
  127. [ $PHP_cache = 3 ] && PHP_extension=apcu
  128. [ $PHP_cache = 4 ] && PHP_extension=eaccelerator
  129. break
  130. fi
  131. done
  132. if [ $ACTION = 1 ];then
  133. Check_PHP_Extension
  134. if [ -e $php_install_dir/etc/php.d/ext-ZendGuardLoader.ini ];then
  135. echo; echo "${CWARNING}You have to install ZendGuardLoader, You need to uninstall it before install $PHP_extension! ${CEND}"; echo; exit 1
  136. else
  137. if [ $PHP_cache = 1 ];then
  138. cd $oneinstack_dir/src
  139. if [[ $PHP_version =~ ^5.[3-4]$ ]];then
  140. Install_ZendOPcache
  141. elif [ "$PHP_version" == '5.5' ];then
  142. src_url=http://www.php.net/distributions/php-$php_5_version.tar.gz && Download_src
  143. tar xzf php-$php_5_version.tar.gz
  144. cd php-$php_5_version/ext/opcache
  145. Install_opcache
  146. elif [ "$PHP_version" == '5.6' ];then
  147. src_url=http://www.php.net/distributions/php-$php_6_version.tar.gz && Download_src
  148. tar xzf php-$php_6_version.tar.gz
  149. cd php-$php_6_version/ext/opcache
  150. Install_opcache
  151. elif [ "$PHP_version" == '7.0' ];then
  152. src_url=http://www.php.net/distributions/php-$php_7_version.tar.gz && Download_src
  153. tar xzf php-$php_7_version.tar.gz
  154. cd php-$php_7_version/ext/opcache
  155. Install_opcache
  156. fi
  157. Check_succ
  158. elif [ $PHP_cache = 2 ];then
  159. if [[ $PHP_version =~ ^5.[3-6]$ ]];then
  160. while :; do
  161. read -p "Please input xcache admin password: " xcache_admin_pass
  162. (( ${#xcache_admin_pass} >= 5 )) && { xcache_admin_md5_pass=`echo -n "$xcache_admin_pass" | md5sum | awk '{print $1}'` ; break ; } || echo "${CFAILURE}xcache admin password least 5 characters! ${CEND}"
  163. done
  164. Install_XCache
  165. Check_succ
  166. else
  167. echo "${CWARNING}Your php does not support XCache! ${CEND}"; exit 1
  168. fi
  169. elif [ $PHP_cache = 3 ];then
  170. if [[ $PHP_version =~ ^5.[3-5]$ ]];then
  171. Install_APCU
  172. Check_succ
  173. else
  174. echo "${CWARNING}Your php does not support APCU! ${CEND}"; exit 1
  175. fi
  176. elif [ $PHP_cache = 4 ];then
  177. if [ "$PHP_version" == '5.3' ];then
  178. Install_eAccelerator-0-9
  179. Check_succ
  180. elif [ "$PHP_version" == '5.4' ];then
  181. Install_eAccelerator-1-0-dev
  182. Check_succ
  183. else
  184. echo "${CWARNING}Your php does not support eAccelerator! ${CEND}"; exit 1
  185. fi
  186. fi
  187. fi
  188. else
  189. Uninstall_succ
  190. fi
  191. ;;
  192. 2)
  193. ACTION_FUN
  194. while :; do echo
  195. echo 'Please select ZendGuardLoader/ionCube:'
  196. echo -e "\t${CMSG}1${CEND}. ZendGuardLoader"
  197. echo -e "\t${CMSG}2${CEND}. ionCube Loader"
  198. read -p "Please input a number:(Default 1 press Enter) " Loader
  199. [ -z "$Loader" ] && Loader=1
  200. if [[ ! $Loader =~ ^[1,2]$ ]];then
  201. echo "${CWARNING}input error! Please only input number 1,2${CEND}"
  202. else
  203. [ $Loader = 1 ] && PHP_extension=ZendGuardLoader
  204. [ $Loader = 2 ] && PHP_extension=ioncube
  205. break
  206. fi
  207. done
  208. if [ $ACTION = 1 ];then
  209. Check_PHP_Extension
  210. if [[ $PHP_version =~ ^5.[3-6]$ ]];then
  211. if [ $Loader = 1 ];then
  212. if [ -e $php_install_dir/etc/php.d/ext-opcache.ini ];then
  213. echo; echo "${CWARNING}You have to install OpCache, You need to uninstall it before install ZendGuardLoader! ${CEND}"; echo; exit 1
  214. else
  215. Install_ZendGuardLoader
  216. Check_succ
  217. fi
  218. elif [ $Loader = 2 ];then
  219. Install_ionCube
  220. Restart_PHP; echo "${CSUCCESS}PHP $PHP_extension module install successfully! ${CEND}";
  221. fi
  222. else
  223. echo; echo "${CWARNING}Your php does not support $PHP_extension! ${CEND}";
  224. fi
  225. else
  226. Uninstall_succ
  227. fi
  228. ;;
  229. 3)
  230. ACTION_FUN
  231. while :; do echo
  232. echo 'Please select ImageMagick/GraphicsMagick:'
  233. echo -e "\t${CMSG}1${CEND}. ImageMagick"
  234. echo -e "\t${CMSG}2${CEND}. GraphicsMagick"
  235. read -p "Please input a number:(Default 1 press Enter) " Magick
  236. [ -z "$Magick" ] && Magick=1
  237. if [[ ! $Magick =~ ^[1,2]$ ]];then
  238. echo "${CWARNING}input error! Please only input number 1,2${CEND}"
  239. else
  240. [ $Magick = 1 ] && PHP_extension=imagick
  241. [ $Magick = 2 ] && PHP_extension=gmagick
  242. break
  243. fi
  244. done
  245. if [ $ACTION = 1 ];then
  246. Check_PHP_Extension
  247. if [ $Magick = 1 ];then
  248. [ ! -d "/usr/local/imagemagick" ] && Install_ImageMagick
  249. Install_php-imagick
  250. Check_succ
  251. elif [ $Magick = 2 ];then
  252. [ ! -d "/usr/local/graphicsmagick" ] && Install_GraphicsMagick
  253. Install_php-gmagick
  254. Check_succ
  255. fi
  256. else
  257. Uninstall_succ
  258. [ -d "/usr/local/imagemagick" ] && rm -rf /usr/local/imagemagick
  259. [ -d "/usr/local/graphicsmagick" ] && rm -rf /usr/local/graphicsmagick
  260. fi
  261. ;;
  262. 4)
  263. ACTION_FUN
  264. while :; do echo
  265. echo 'Please select memcache/memcached PHP Extension:'
  266. echo -e "\t${CMSG}1${CEND}. memcache PHP Extension"
  267. echo -e "\t${CMSG}2${CEND}. memcached PHP Extension"
  268. echo -e "\t${CMSG}3${CEND}. memcache/memcached PHP Extension"
  269. read -p "Please input a number:(Default 1 press Enter) " Memcache
  270. [ -z "$Memcache" ] && Memcache=1
  271. if [[ ! $Memcache =~ ^[1-3]$ ]];then
  272. echo "${CWARNING}input error! Please only input number 1,2,3${CEND}"
  273. else
  274. [ $Memcache = 1 ] && PHP_extension=memcache
  275. [ $Memcache = 2 ] && PHP_extension=memcached
  276. break
  277. fi
  278. done
  279. if [ $ACTION = 1 ];then
  280. if [ $Memcache = 1 ];then
  281. [ ! -d "$memcached_install_dir/include/memcached" ] && Install_memcached
  282. Check_PHP_Extension
  283. Install_php-memcache
  284. Check_succ
  285. elif [ $Memcache = 2 ];then
  286. [ ! -d "$memcached_install_dir/include/memcached" ] && Install_memcached
  287. Check_PHP_Extension
  288. Install_php-memcached
  289. Check_succ
  290. elif [ $Memcache = 3 ];then
  291. [ ! -d "$memcached_install_dir/include/memcached" ] && Install_memcached
  292. PHP_extension=memcache && Check_PHP_Extension
  293. Install_php-memcache
  294. PHP_extension=memcached && Check_PHP_Extension
  295. Install_php-memcached
  296. [ -f "`$php_install_dir/bin/php-config --extension-dir`/memcache.so" -a "`$php_install_dir/bin/php-config --extension-dir`/memcached.so" ] && { Restart_PHP; echo;echo "${CSUCCESS}PHP memcache/memcached module install successfully! ${CEND}"; }
  297. fi
  298. else
  299. PHP_extension=memcache && Uninstall_succ
  300. PHP_extension=memcached && Uninstall_succ
  301. [ -e "$memcached_install_dir" ] && { service memcached stop > /dev/null 2>&1; rm -rf $memcached_install_dir /etc/init.d/memcached /usr/bin/memcached; }
  302. fi
  303. ;;
  304. 5)
  305. ACTION_FUN
  306. PHP_extension=redis
  307. if [ $ACTION = 1 ];then
  308. [ ! -d "$redis_install_dir" ] && Install_redis-server
  309. Check_PHP_Extension
  310. Install_php-redis
  311. else
  312. Uninstall_succ
  313. [ -e "$redis_install_dir" ] && { service redis-server stop > /dev/null 2>&1; rm -rf $redis_install_dir /etc/init.d/redis-server /usr/local/bin/redis-*; }
  314. fi
  315. ;;
  316. q)
  317. exit
  318. ;;
  319. esac
  320. fi
  321. done