upgrade_php.sh 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/bin/bash
  2. # Author: yeho <lj2007331 AT gmail.com>
  3. # BLOG: https://blog.linuxeye.com
  4. #
  5. # Version: 1.0-Alpha Jun 15,2015 lj2007331 AT gmail.com
  6. # Notes: OneinStack for CentOS/RadHat 5+ Debian 6+ and Ubuntu 12+
  7. #
  8. # Project home page:
  9. # http://oneinstack.com
  10. # Check if user is root
  11. [ $(id -u) != "0" ] && { echo -e "\033[31mError: You must be root to run this script\033[0m"; exit 1; }
  12. export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
  13. clear
  14. printf "
  15. #######################################################################
  16. # OneinStack for CentOS/RadHat 5+ Debian 6+ and Ubuntu 12+ #
  17. # Upgrade PHP for OneinStack #
  18. # For more information please visit http://oneinstack.com #
  19. #######################################################################
  20. "
  21. cd src
  22. . ../options.conf
  23. [ ! -e "$php_install_dir" ] && echo -e "\033[31mThe PHP is not installed on your system!\033[0m " && exit 1
  24. get_char()
  25. {
  26. SAVEDSTTY=`stty -g`
  27. stty -echo
  28. stty cbreak
  29. dd if=/dev/tty bs=1 count=1 2> /dev/null
  30. stty -raw
  31. stty echo
  32. stty $SAVEDSTTY
  33. }
  34. echo
  35. Old_php_version=`$php_install_dir/bin/php -r 'echo PHP_VERSION;'`
  36. echo -e "Current PHP Version: \033[32m$Old_php_version\033[0m"
  37. while :
  38. do
  39. echo
  40. read -p "Please input upgrade PHP Version: " php_version
  41. if [ "${php_version%.*}" == "${Old_php_version%.*}" ]; then
  42. if [ "${php_version##*.}" -ge "${Old_php_version##*.}" ]; then
  43. [ ! -e "php-$php_version.tar.gz" ] && wget -c http://www.php.net/distributions/php-$php_version.tar.gz > /dev/null 2>&1
  44. if [ -e "php-$php_version.tar.gz" ];then
  45. echo -e "Download \033[32mphp-$php_version.tar.gz\033[0m successfully! "
  46. else
  47. echo -e "\033[31mIt does not exist!\033[0m"
  48. fi
  49. break
  50. else
  51. echo -e "Error: You must input PHP version not less than \033[32m$Old_php_version\033[0m!! "
  52. fi
  53. else
  54. echo -e "\033[31minput error!\033[0m Please only input '\033[32m${Old_php_version%.*}.xx' \033[0m"
  55. fi
  56. done
  57. if [ -e "php-$php_version.tar.gz" ];then
  58. echo -e "\033[32mphp-$php_version.tar.gz\033[0m [found]"
  59. echo "Press Ctrl+c to cancel or Press any key to continue..."
  60. char=`get_char`
  61. tar xzf php-$php_version.tar.gz
  62. [ ! -e "fpm-race-condition.patch" ] && wget -O fpm-race-condition.patch 'https://bugs.php.net/patch-display.php?bug_id=65398&patch=fpm-race-condition.patch&revision=1375772074&download=1'
  63. patch -d php-$php_version -p0 < fpm-race-condition.patch
  64. cd php-$php_version
  65. make clean
  66. $php_install_dir/bin/php -i |grep 'Configure Command' | awk -F'=>' '{print $2}' | bash
  67. make ZEND_EXTRA_LIBS='-liconv'
  68. make install
  69. cd ..
  70. echo "Restarting php-fpm..."
  71. /etc/init.d/php-fpm restart
  72. echo -e "You have \033[32msuccessfully\033[0m upgrade from \033[32m$Old_php_version\033[0m to \033[32m$php_version\033[0m"
  73. fi