1
0

upgrade_php.sh 3.1 KB

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