upgrade_php.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. Upgrade_PHP() {
  11. pushd ${oneinstack_dir}/src > /dev/null
  12. [ ! -e "${php_install_dir}" ] && echo "${CWARNING}PHP is not installed on your system! ${CEND}" && exit 1
  13. OLD_php_ver=`${php_install_dir}/bin/php-config --version`
  14. Latest_php_ver=`curl --connect-timeout 2 -m 3 -s https://www.php.net/releases/active.php | python -mjson.tool | awk '/version/{print $2}' | sed 's/"//g' | grep "${OLD_php_ver%.*}"`
  15. Latest_php_ver=${Latest_php_ver:-5.5.38}
  16. echo
  17. echo "Current PHP Version: ${CMSG}$OLD_php_ver${CEND}"
  18. while :; do echo
  19. [ "${php_flag}" != 'y' ] && read -e -p "Please input upgrade PHP Version(Default: $Latest_php_ver): " NEW_php_ver
  20. NEW_php_ver=${NEW_php_ver:-${Latest_php_ver}}
  21. if [ "${NEW_php_ver%.*}" == "${OLD_php_ver%.*}" ]; then
  22. [ ! -e "php-${NEW_php_ver}.tar.gz" ] && wget --no-check-certificate -c https://secure.php.net/distributions/php-${NEW_php_ver}.tar.gz > /dev/null 2>&1
  23. if [ -e "php-${NEW_php_ver}.tar.gz" ]; then
  24. echo "Download [${CMSG}php-${NEW_php_ver}.tar.gz${CEND}] successfully! "
  25. else
  26. echo "${CWARNING}PHP version does not exist! ${CEND}"
  27. fi
  28. break
  29. else
  30. echo "${CWARNING}input error! ${CEND}Please only input '${CMSG}${OLD_php_ver%.*}.xx${CEND}'"
  31. [ "${php_flag}" == 'y' ] && exit
  32. fi
  33. done
  34. if [ -e "php-${NEW_php_ver}.tar.gz" ]; then
  35. echo "[${CMSG}php-${NEW_php_ver}.tar.gz${CEND}] found"
  36. if [ "${php_flag}" != 'y' ]; then
  37. echo "Press Ctrl+c to cancel or Press any key to continue..."
  38. char=`get_char`
  39. fi
  40. tar xzf php-${NEW_php_ver}.tar.gz
  41. src_url=http://mirrors.linuxeye.com/oneinstack/src/fpm-race-condition.patch && Download_src
  42. patch -d php-${NEW_php_ver} -p0 < fpm-race-condition.patch
  43. pushd php-${NEW_php_ver}
  44. if [[ "${OLD_php_ver%.*}" =~ ^7.[1-4]$|^8.[0-1]$ ]] && [ -e ext/openssl/openssl.c ] && ! grep -Eqi '^#ifdef RSA_SSLV23_PADDING' ext/openssl/openssl.c; then
  45. sed -i '/OPENSSL_SSLV23_PADDING/i#ifdef RSA_SSLV23_PADDING' ext/openssl/openssl.c
  46. sed -i '/OPENSSL_SSLV23_PADDING/a#endif' ext/openssl/openssl.c
  47. fi
  48. make clean
  49. export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/:$PKG_CONFIG_PATH
  50. ${php_install_dir}/bin/php -i |grep 'Configure Command' | awk -F'=>' '{print $2}' | bash
  51. make ZEND_EXTRA_LIBS='-liconv' -j ${THREAD}
  52. if [ -e "${apache_install_dir}/bin/httpd" ]; then
  53. echo "Stoping apache..."
  54. service httpd stop
  55. make install
  56. echo "Starting apache..."
  57. service httpd start
  58. else
  59. echo "Stoping php-fpm..."
  60. service php-fpm stop
  61. make install
  62. echo "Starting php-fpm..."
  63. service php-fpm start
  64. fi
  65. popd > /dev/null
  66. echo "You have ${CMSG}successfully${CEND} upgrade from ${CWARNING}$OLD_php_ver${CEND} to ${CWARNING}${NEW_php_ver}${CEND}"
  67. rm -rf php-${NEW_php_ver}
  68. fi
  69. popd > /dev/null
  70. }