3 Commits
2 changed files with 34 additions and 15 deletions
+2 -2
View File
@@ -1,7 +1,7 @@
# RHEL PHP # RHEL PHP
在RHEL Linux中自动安装PHP 在RHEL Linux中自动安装PHP
本脚本会自动检测RHEL系统和是否位于中国,安装对应的Remi源(中国的RHEL9服务器将安装中国特色源) 本脚本会自动检测系统的 RHEL 主版本,并安装对应版本的 Remi 仓库包。检测到服务器位于中国大陆时,会在安装 PHP 前将 Remi 仓库(包括 `remi-safe` 和 `remi-modular`)切换到清华大学 TUNA 镜像,适用于脚本支持的各个 RHEL 主版本。其他地区使用 Remi 仓库包的默认配置。
并检查系统空闲内存,对于内存<2G,且空余硬盘空间>5G的系统,将自动装载4G的swap以防止yum被杀 并检查系统空闲内存,对于内存<2G,且空余硬盘空间>5G的系统,将自动装载4G的swap以防止yum被杀
@@ -13,4 +13,4 @@
wget https://git.laysense.com/laysense/rhelphp/raw/branch/main/rhelphp.bash wget https://git.laysense.com/laysense/rhelphp/raw/branch/main/rhelphp.bash
bash ./rhelphp.bash bash ./rhelphp.bash
+32 -13
View File
@@ -43,20 +43,39 @@ fi
# 判断服务器是否位于中国大陆 # 判断服务器是否位于中国大陆
is_china=$(curl -s ping0.cc/geo | grep -q '中国' && echo "yes" || echo "no") # 调用API接口检查地理位置是否在中国大陆 location=$(curl -fsS --max-time 10 https://ping0.cc/geo | sed -n '2p')
location=${location%% — *}
# 设置对应的安装源URL is_china=no
if [[ "$is_china" == "yes" && "$rhel_version" -eq 9 ]]; then if [[ "$location" == 中国* && ! "$location" =~ 香港|澳门|澳門|台湾|臺灣|台灣|臺湾 ]]; then
# 如果是中国大陆且RHEL版本为9,使用特定的国内源 is_china=yes
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"
fi fi
# 安装 Remi 仓库 # 安装对应系统版本的标准 Remi 仓库包
echo "Installing Remi repository from $repo_url..." # 输出安装源信息 remi_mirror="https://mirrors.tuna.tsinghua.edu.cn/remi"
yum -y install "$repo_url" # 使用yum安装指定的remi-release包 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版本 # 提示用户输入PHP版本
read -p "Enter the PHP version to install (e.g., 80, 8.0, php80, php8.0): " php_version read -p "Enter the PHP version to install (e.g., 80, 8.0, php80, php8.0): " php_version
@@ -108,7 +127,7 @@ if [[ $? -eq 0 ]]; then
# 下载并安装Composer # 下载并安装Composer
php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');" # 下载Composer安装脚本 php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');" # 下载Composer安装脚本
php composer-setup.php # 执行Composer安装脚本 php composer-setup.php # 执行Composer安装脚本
mv composer.phar /usr/local/composer # 将Composer可执行文件移动到全局路径 mv composer.phar /usr/bin/composer # 将Composer可执行文件移动到全局路径
# 如果是中国大陆服务器,配置阿里云镜像 # 如果是中国大陆服务器,配置阿里云镜像
if [[ "$is_china" == "yes" ]]; then if [[ "$is_china" == "yes" ]]; then