环境:centOS stream 9\php8.3.27
系统自带的cURL的版本:7.66,版本太低了,在请求微信公众号或小程序时,使用easywechat插件请求时,报错;通过多方查找原因,得知cURL版本过低造成的;通过AI创建了一个自动执行的脚本,来升级cURL;
#!/usr/bin/env bash set -e CURL_VERSION="8.17.0" CURL_FILE="curl-${CURL_VERSION}.tar.xz" CURL_URL="https://curl.se/download/${CURL_FILE}" SRC_DIR="/usr/local/src/curl-${CURL_VERSION}" echo "==============================================" echo " 🚀 Installing curl ${CURL_VERSION} for CentOS Stream 9" echo " 🚀 Supports: OpenSSL + HTTP/2 (WeChat APIs)" echo "==============================================" # ------------------------------------------------------ # 1. Install dependencies # ------------------------------------------------------ echo "➡️ Installing build dependencies..." sudo dnf groupinstall -y "Development Tools" sudo dnf install -y openssl-devel libtool autoconf automake pkgconfig zlib-devel \ libpsl-devel libzstd-devel brotli-devel libnghttp2-devel # ------------------------------------------------------ # 2. Prepare source directory # ------------------------------------------------------ echo "➡️ Downloading curl ${CURL_VERSION}..." sudo rm -rf "${SRC_DIR}" sudo mkdir -p "${SRC_DIR}" cd "${SRC_DIR}" sudo curl -LO "${CURL_URL}" echo "➡️ Extracting..." sudo tar -xf "${CURL_FILE}" --strip-components=1 # ------------------------------------------------------ # 3. Configure with OpenSSL + HTTP2 # ------------------------------------------------------ echo "➡️ Configuring curl (OpenSSL + HTTP/2)..." sudo ./configure --with-openssl --with-nghttp2 # ------------------------------------------------------ # 4. Build # ------------------------------------------------------ echo "➡️ Building curl..." sudo make -j$(nproc) # ------------------------------------------------------ # 5. Install curl # ------------------------------------------------------ echo "➡️ Installing curl..." sudo make install sudo ldconfig # ------------------------------------------------------ # 6. Validate curl version # ------------------------------------------------------ echo "➡️ Checking curl version..." curl --version # ------------------------------------------------------ # 7. Restart PHP-FPM if exists # ------------------------------------------------------ PHP_FPM_SERVICE="/etc/init.d/php-fpm-84" if [ -x "$PHP_FPM_SERVICE" ]; then echo "➡️ Restarting PHP 8.4 FPM..." "$PHP_FPM_SERVICE" restart else echo "⚠️ PHP 8.4 FPM service not found." fi # ------------------------------------------------------ # 8. Validate PHP curl version # ------------------------------------------------------ if command -v php >/dev/null 2>&1; then echo "➡️ PHP curl info:" php -i | grep -E "cURL support|cURL Information|HTTP2" else echo "ℹ️ PHP not found, skipping PHP validation." fi echo "" echo "==============================================" echo " 🎉 Installation complete!" echo " 🎉 curl ${CURL_VERSION} (OpenSSL + HTTP/2) is now ready!" echo "=============================================="sudo ./install_curl_8_17_centos9.sh搞定;