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

87 lines
2.6 KiB
Bash

#!/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}
php_path="${setup_path}/server/php/${version}"
php_memcached_version="3.4.0"
Install() {
# 检查是否已经安装
is_install=$(cat ${php_path}/etc/php.ini | grep '^extension=memcached$')
if [ "${is_install}" != "" ]; then
error "PHP-${version} memcached already installed"
fi
# 安装依赖
if [ ${OS} == "rhel" ]; then
dnf makecache -y
dnf install libmemcached-devel libzstd-devel -y
elif [ ${OS} == "debian" ] || [ ${OS} == "ubuntu" ]; then
apt-get update
apt-get install libmemcached-dev libzstd-dev -y
else
error "Unsupported operating system"
fi
if [ "$?" != "0" ]; then
error "Failed to install dependencies"
fi
cd ${php_path}/src/ext
rm -rf memcached
rm -rf php-memcached-${php_memcached_version}.zip
dl "${php_path}/src/ext" "/php_exts/php-memcached-${php_memcached_version}.zip"
unzip -o php-memcached-${php_memcached_version}.zip
mv php-memcached-${php_memcached_version} memcached
rm -f php-memcached-${php_memcached_version}.zip
cd memcached
${php_path}/bin/phpize
./configure --with-php-config=${php_path}/bin/php-config --enable-memcached-session --enable-memcached-json --enable-memcached-sasl --with-zstd
make
if [ "$?" != "0" ]; then
rm -rf ${php_path}/src/ext/memcached
error "PHP-${version} memcached compilation failed"
fi
make install
if [ "$?" != "0" ]; then
rm -rf ${php_path}/src/ext/memcached
error "PHP-${version} memcached installation failed"
fi
sed -i '/;panel/a\extension=memcached' ${php_path}/etc/php.ini
# 重载PHP
systemctl reload php-fpm-${version}.service
echo -e $HR
echo "PHP-${version} memcached installation successful"
}
Uninstall() {
# 检查是否已经安装
is_install=$(cat ${php_path}/etc/php.ini | grep '^extension=memcached$')
if [ "${is_install}" == "" ]; then
error "PHP-${version} memcached not installed"
fi
sed -i '/extension=memcached/d' ${php_path}/etc/php.ini
# 重载PHP
systemctl reload php-fpm-${version}.service
echo -e $HR
echo "PHP-${version} memcached uninstall successful"
}
if [ "$action" == 'install' ]; then
Install
fi
if [ "$action" == 'uninstall' ]; then
Uninstall
fi