Files
download/php_exts/official.sh
耗子 758e1c8799
All checks were successful
Generate Checksums / checksums (push) Successful in 46s
feat: 清理提交
2026-01-31 07:03:45 +08:00

148 lines
4.6 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:$PATH
source <(curl -f -s --connect-timeout 10 --retry 3 https://dl.acepanel.net/public.sh)
if [ $? -ne 0 ]; then
echo "Download public.sh failed, please check the network or try again later."
exit 1
fi
action=${1}
version=${2}
extension=${3} # 扩展名称
php_path="${setup_path}/server/php/${version}"
add_args="" # 附加参数
Install() {
# 检查是否已经安装
is_install=$(cat ${php_path}/etc/php.ini | grep "^extension=${extension}$")
if [ "${is_install}" != "" ]; then
error "PHP-${version} ${extension} already installed"
fi
# 安装依赖
if [ "${extension}" == "snmp" ]; then
if [ ${OS} == "rhel" ]; then
dnf install -y net-snmp-devel
elif [ ${OS} == "debian" ] || [ ${OS} == "ubuntu" ]; then
apt-get install -y libsnmp-dev
fi
fi
if [ "${extension}" == "ldap" ]; then
if [ ${OS} == "rhel" ]; then
dnf install -y openldap-devel
ln -sf /usr/lib64/libldap* /usr/lib
elif [ ${OS} == "debian" ] || [ ${OS} == "ubuntu" ]; then
apt-get install -y libldap2-dev
ln -sf /usr/lib/x86_64-linux-gnu/libldap* /usr/lib
fi
fi
if [ "${extension}" == "imap" ]; then
if [ ${OS} == "rhel" ]; then
# RHEL 9 的仓库中没有 libc-client-devel待考虑
dnf install -y libc-client-devel
elif [ ${OS} == "debian" ] || [ ${OS} == "ubuntu" ]; then
apt-get install -y libc-client-dev
fi
add_args="--with-imap --with-imap-ssl --with-kerberos"
fi
if [ "${extension}" == "enchant" ]; then
if [ ${OS} == "rhel" ]; then
dnf install -y enchant-devel
elif [ ${OS} == "debian" ] || [ ${OS} == "ubuntu" ]; then
apt-get install -y libenchant-2-dev
fi
fi
if [ "${extension}" == "pspell" ]; then
if [ ${OS} == "rhel" ]; then
dnf install -y aspell-devel
elif [ ${OS} == "debian" ] || [ ${OS} == "ubuntu" ]; then
apt-get install -y libpspell-dev
fi
fi
if [ "${extension}" == "gmp" ]; then
if [ ${OS} == "rhel" ]; then
dnf install -y gmp-devel
elif [ ${OS} == "debian" ] || [ ${OS} == "ubuntu" ]; then
apt-get install -y libgmp-dev
fi
fi
if [ "${extension}" == "gettext" ]; then
if [ ${OS} == "rhel" ]; then
dnf install -y gettext-devel
elif [ ${OS} == "debian" ] || [ ${OS} == "ubuntu" ]; then
apt-get install -y libgettextpo-dev
fi
fi
if [ "${extension}" == "bz2" ]; then
if [ ${OS} == "rhel" ]; then
dnf install -y bzip2-devel
elif [ ${OS} == "debian" ] || [ ${OS} == "ubuntu" ]; then
apt-get install -y libbz2-dev
fi
fi
if [ "${extension}" == "zip" ]; then
if [ ${OS} == "rhel" ]; then
dnf install -y libzip-devel
elif [ ${OS} == "debian" ] || [ ${OS} == "ubuntu" ]; then
apt-get install -y libzip-dev
fi
fi
if [ "$?" != "0" ]; then
error "Failed to install dependencies"
fi
if [ "${extension}" == "pdo_pgsql" ]; then
add_args="--with-pdo-pgsql=${setup_path}/server/postgresql"
fi
if [ "${extension}" == "pgsql" ]; then
add_args="--with-pgsql=${setup_path}/server/postgresql"
fi
# 安装扩展
if [ ! -d ${php_path}/src/ext/${extension} ]; then
error "PHP-${version} ${extension} does not exist"
fi
cd ${php_path}/src/ext/${extension}
${php_path}/bin/phpize
./configure --with-php-config=${php_path}/bin/php-config ${add_args}
make
if [ "$?" != "0" ]; then
error "PHP-${version} ${extension} compilation failed"
fi
make install
if [ "$?" != "0" ]; then
error "PHP-${version} ${extension} installation failed"
fi
sed -i "/;panel/a\extension=${extension}" ${php_path}/etc/php.ini
# 重载PHP
systemctl reload php-fpm-${version}.service
echo -e $HR
echo "PHP-${version} ${extension} installation successful"
}
Uninstall() {
# 检查是否已经安装
is_install=$(cat ${php_path}/etc/php.ini | grep "^extension=${extension}$")
if [ "${is_install}" == "" ]; then
error "PHP-${version} ${extension} not installed"
fi
sed -i "/extension=${extension}/d" ${php_path}/etc/php.ini
# 重载PHP
systemctl reload php-fpm-${version}.service
echo -e $HR
echo "PHP-${version} ${extension} uninstall successful"
}
if [ "$action" == 'install' ]; then
Install
fi
if [ "$action" == 'uninstall' ]; then
Uninstall
fi