forked from laysense/rhelphp
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
66fd3ba06f |
@@ -1,7 +1,7 @@
|
||||
# RHEL PHP
|
||||
在RHEL Linux中自动安装PHP
|
||||
|
||||
本脚本会自动检测RHEL系统和是否位于中国,安装对应的Remi源(中国的RHEL9服务器将安装中国特色源)
|
||||
本脚本会自动检测系统的 RHEL 主版本,并安装对应版本的 Remi 仓库包。检测到服务器位于中国大陆时,会在安装 PHP 前将 Remi 仓库(包括 `remi-safe` 和 `remi-modular`)切换到清华大学 TUNA 镜像,适用于脚本支持的各个 RHEL 主版本。其他地区使用 Remi 仓库包的默认配置。
|
||||
|
||||
并检查系统空闲内存,对于内存<2G,且空余硬盘空间>5G的系统,将自动装载4G的swap以防止yum被杀
|
||||
|
||||
|
||||
+31
-12
@@ -43,20 +43,39 @@ fi
|
||||
|
||||
|
||||
# 判断服务器是否位于中国大陆
|
||||
is_china=$(curl -s ping0.cc/geo | grep -q '中国' && echo "yes" || echo "no") # 调用API接口检查地理位置是否在中国大陆
|
||||
|
||||
# 设置对应的安装源URL
|
||||
if [[ "$is_china" == "yes" && "$rhel_version" -eq 9 ]]; then
|
||||
# 如果是中国大陆且RHEL版本为9,使用特定的国内源
|
||||
repo_url="https://git.laysense.com/enoch/RemiTuna/raw/branch/main/remi-release-9.4-2.el9.remi.noarch.rpm"
|
||||
else
|
||||
# 否则使用TUNA的Remi源,根据RHEL版本动态选择
|
||||
repo_url="https://mirrors.tuna.tsinghua.edu.cn/remi/enterprise/remi-release-$rhel_version.rpm"
|
||||
location=$(curl -fsS --max-time 10 https://ping0.cc/geo | sed -n '2p')
|
||||
location=${location%% — *}
|
||||
is_china=no
|
||||
if [[ "$location" == 中国* && ! "$location" =~ 香港|澳门|澳門|台湾|臺灣|台灣|臺湾 ]]; then
|
||||
is_china=yes
|
||||
fi
|
||||
|
||||
# 安装 Remi 仓库
|
||||
echo "Installing Remi repository from $repo_url..." # 输出安装源信息
|
||||
yum -y install "$repo_url" # 使用yum安装指定的remi-release包
|
||||
# 安装对应系统版本的标准 Remi 仓库包
|
||||
remi_mirror="https://mirrors.tuna.tsinghua.edu.cn/remi"
|
||||
repo_url="$remi_mirror/enterprise/remi-release-$rhel_version.rpm"
|
||||
repo_install_options=()
|
||||
if [[ "$is_china" == "yes" ]]; then
|
||||
# 避免安装仓库包时访问机器上已有的 Remi 镜像列表
|
||||
repo_install_options+=("--disablerepo=remi*")
|
||||
fi
|
||||
|
||||
echo "Installing Remi repository from $repo_url..."
|
||||
if ! yum -y "${repo_install_options[@]}" install "$repo_url"; then
|
||||
echo "Failed to install the Remi repository package." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ "$is_china" == "yes" ]]; then
|
||||
# 启用 Remi RPM 提供的 baseurl,并保留各仓库原有的路径、变量和 GPG 配置。
|
||||
echo "Switching Remi repositories to the Tsinghua mirror..."
|
||||
if ! sed -E -i \
|
||||
-e "s|^[[:blank:]]*#?[[:blank:]]*baseurl[[:blank:]]*=[[:blank:]]*https?://rpms\.remirepo\.net/enterprise/|baseurl=$remi_mirror/enterprise/|" \
|
||||
-e 's/^([[:blank:]]*(mirrorlist|metalink)[[:blank:]]*=)/#\1/' \
|
||||
/etc/yum.repos.d/remi*.repo; then
|
||||
echo "Failed to switch Remi repositories to the Tsinghua mirror." >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# 提示用户输入PHP版本
|
||||
read -p "Enter the PHP version to install (e.g., 80, 8.0, php80, php8.0): " php_version
|
||||
|
||||
Reference in New Issue
Block a user