#!/bin/bash export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:$PATH : ' Copyright 2022 HaoZi Technology Co., Ltd. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ' HR="+----------------------------------------------------" ARCH=$(uname -m) OS=$(source /etc/os-release && { [[ "$ID" == "debian" ]] && echo "debian"; } || { [[ "$ID" == "centos" ]] || [[ "$ID" == "rhel" ]] || [[ "$ID" == "rocky" ]] || [[ "$ID" == "almalinux" ]] && echo "centos"; } || echo "unknown") downloadUrl="https://dl.cdn.haozi.net/panel/php" setupPath="/www" phpVersion="${1}" phpPath="${setupPath}/server/php/${phpVersion}" # 安装依赖 if [ "${OS}" == "centos" ]; then dnf install dnf-plugins-core -y dnf install epel-release -y dnf config-manager --set-enabled epel dnf config-manager --set-enabled PowerTools dnf config-manager --set-enabled powertools dnf config-manager --set-enabled CRB dnf config-manager --set-enabled Crb dnf config-manager --set-enabled crb /usr/bin/crb enable dnf makecache dnf groupinstall "Development Tools" -y dnf install autoconf glibc-headers gdbm-devel gd gd-devel perl oniguruma-devel libsodium-devel libxml2-devel sqlite-devel libzip-devel bzip2-devel xz-devel libpng-devel libjpeg-devel libwebp-devel freetype-devel gmp-devel openssl-devel readline-devel libxslt-devel libcurl-devel pkgconfig libedit-devel zlib-devel pcre-devel crontabs libicu libicu-devel c-ares -y elif [ "${OS}" == "debian" ]; then apt update apt install build-essential autoconf libc6-dev libgdbm-dev libgd-tools libgd-dev perl libonig-dev libsodium-dev libxml2-dev libsqlite3-dev libzip-dev libbz2-dev liblzma-dev libpng-dev libjpeg-dev libwebp-dev libfreetype6-dev libgmp-dev libssl-dev libreadline-dev libxslt1-dev libcurl4-openssl-dev pkg-config libedit-dev zlib1g-dev libpcre3-dev cron libicu-dev libc-ares2 libc-ares-dev -y else echo -e $HR echo "错误:耗子Linux面板不支持该系统" exit 1 fi # 准备安装目录 rm -rf ${phpPath} mkdir -p ${phpPath} cd ${phpPath} # 下载源码 if [ "${phpVersion}" == "74" ]; then wget -O ${phpPath}/php-${phpVersion}.tar.gz ${downloadUrl}/php-7.4.33.tar.gz elif [ "${phpVersion}" == "80" ]; then wget -O ${phpPath}/php-${phpVersion}.tar.gz ${downloadUrl}/php-8.0.29.tar.gz elif [ "${phpVersion}" == "81" ]; then wget -O ${phpPath}/php-${phpVersion}.tar.gz ${downloadUrl}/php-8.1.21.tar.gz elif [ "${phpVersion}" == "82" ]; then wget -O ${phpPath}/php-${phpVersion}.tar.gz ${downloadUrl}/php-8.2.8.tar.gz else echo -e $HR echo "错误:PHP-${phpVersion}不支持,请检查版本号是否正确。" exit 1 fi if [ "$?" != "0" ]; then echo -e $HR echo "错误:PHP-${phpVersion}下载失败,请检查网络是否正常。" exit 1 fi tar -xvf php-${phpVersion}.tar.gz rm -f php-${phpVersion}.tar.gz mv php-* src if [ "${phpVersion}" -le "80" ]; then wget -T 120 -O ${phpPath}/openssl-1.1.1u.tar.gz ${downloadUrl}/openssl/openssl-1.1.1u.tar.gz tar -zxvf openssl-1.1.1u.tar.gz rm -f openssl-1.1.1u.tar.gz mv openssl-1.1.1u openssl cd openssl ./config --prefix=/usr/local/openssl-1.1 --openssldir=/usr/local/openssl-1.1 make -j$(nproc) make install echo "/usr/local/openssl-1.1/lib" > /etc/ld.so.conf.d/openssl-1.1.conf ldconfig cd .. rm -rf openssl export CFLAGS="-I/usr/local/openssl-1.1/include -I/usr/local/curl/include" export LIBS="-L/usr/local/openssl-1.1/lib -L/usr/local/curl/lib" fi # 配置 cd src ./configure --prefix=${phpPath} --with-config-file-path=${phpPath}/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-freetype --with-jpeg --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-intl --enable-pcntl --enable-ftp --enable-gd --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-soap --with-gettext --enable-fileinfo --enable-opcache --with-sodium --with-webp # 编译安装 make -j${nproc} make install if [ ! -f "${phpPath}/bin/php" ]; then echo -e $HR echo "错误:PHP-${phpVersion}安装失败,请截图错误信息寻求帮助!" rm -rf ${phpPath} exit 1 fi # 创建php配置 mkdir -p ${phpPath}/etc \cp php.ini-production ${phpPath}/etc/php.ini # 安装zip拓展 cd ${phpPath}/src/ext/zip ${phpPath}/bin/phpize ./configure --with-php-config=${phpPath}/bin/php-config make -j${cpuCore} make install if [ "$?" != "0" ]; then echo -e $HR echo "错误:PHP-${phpVersion} zip拓展安装失败,请截图错误信息寻求帮助。" exit 1 fi cd ../../ # 写入拓展标记位 echo ";下方标记位禁止删除,否则将导致PHP拓展无法正常安装!" >>${phpPath}/etc/php.ini echo ";haozi" >>${phpPath}/etc/php.ini # 写入zip拓展到php配置 echo "extension=zip" >>${phpPath}/etc/php.ini # 设置软链接 rm -f /usr/bin/php-${phpVersion} rm -f /usr/bin/pear rm -f /usr/bin/pecl ln -sf ${phpPath}/bin/php /usr/bin/php ln -sf ${phpPath}/bin/php /usr/bin/php-${phpVersion} ln -sf ${phpPath}/bin/phpize /usr/bin/phpize ln -sf ${phpPath}/bin/pear /usr/bin/pear ln -sf ${phpPath}/bin/pecl /usr/bin/pecl ln -sf ${phpPath}/sbin/php-fpm /usr/bin/php-fpm-${phpVersion} # 设置fpm cat >${phpPath}/etc/php-fpm.conf </www/server/openresty/conf/enable-php-${phpVersion}.conf <