1111
1212# shellcheck disable=SC2155 # Allow declare and assign on same line for better readability
1313
14- PHPVM_VERSION=" 1.12.1 "
14+ PHPVM_VERSION=" 1.12.2 "
1515
1616# Test mode flag
1717PHPVM_TEST_MODE=" ${PHPVM_TEST_MODE:- false} "
@@ -931,11 +931,11 @@ pkg_search_php() {
931931 fi
932932 ;;
933933 dnf)
934- # Check for module stream availability (preferred for versioned PHP)
935- if dnf module list php 2> /dev/null | command grep -Eq " php[[:space:]]+ ${version} [[:space:]]| ${ version} [[:space:]]+\[ " ; then
934+ # Use stream resolution to handle both Remi (remi-X.Y) and AppStream (X.Y) naming
935+ if [ -n " $( dnf_resolve_php_stream " $ version" ) " ] ; then
936936 return 0
937937 fi
938- # If any php module exists, signal "some versions exist"
938+ # If any php module exists, signal "some versions exist but not this one "
939939 if dnf module list php 2> /dev/null | command grep -q " ^php" ; then
940940 return 2
941941 fi
@@ -1204,6 +1204,39 @@ check_remi_repository() {
12041204 fi
12051205}
12061206
1207+ # Return the DNF major version (4 or 5), or 0 if dnf not found
1208+ dnf_major_version () {
1209+ command dnf --version 2> /dev/null | command awk ' NR==1{split($1,a,"."); print a[1]+0}'
1210+ }
1211+
1212+ # Resolve the actual dnf module stream name for a PHP X.Y version.
1213+ # Remi uses "remi-X.Y", RHEL AppStream uses "X.Y".
1214+ # Prints the stream name (e.g. "remi-8.2") or nothing if not found.
1215+ dnf_resolve_php_stream () {
1216+ local version=" $1 "
1217+ command dnf module list php 2> /dev/null | command awk -v ver=" $version " '
1218+ $1 == "php" {
1219+ stream = $2
1220+ # Exact match (AppStream: "8.2") or suffix match (Remi: "remi-8.2")
1221+ if (stream == ver || substr(stream, length(stream) - length(ver)) == "-" ver) {
1222+ # Prefer remi- streams when available; collect all and pick last-or-remi
1223+ if (substr(stream, 1, 5) == "remi-") { remi = stream }
1224+ else { plain = stream }
1225+ }
1226+ }
1227+ END { if (remi != "") print remi; else if (plain != "") print plain }
1228+ '
1229+ }
1230+
1231+ # Return 0 if the given php module stream is currently enabled, 1 otherwise.
1232+ dnf_stream_enabled () {
1233+ local stream=" $1 "
1234+ command dnf module list php 2> /dev/null | command awk -v s=" $stream " '
1235+ $1 == "php" && $2 == s { if (index($3, "[e]") || index($4, "[e]") || index($0, "[e]")) found=1 }
1236+ END { exit (found ? 0 : 1) }
1237+ '
1238+ }
1239+
12071240# Detect if PHP packages are available in current repositories
12081241detect_php_availability () {
12091242 local version=" $1 "
@@ -1218,9 +1251,23 @@ suggest_repository_setup() {
12181251 local version=" $1 "
12191252 local major_minor
12201253 local major_version
1254+ local dnf_ver
1255+
1256+ # Emit the correct "dnf config-manager" syntax for the installed dnf version.
1257+ # DNF5 (Fedora 41+) removed --set-enabled; use "setopt <repo>.enabled=1" instead.
1258+ _dnf_enable_repo_cmd () {
1259+ local repo=" $1 "
1260+ dnf_ver=$( dnf_major_version)
1261+ if [ " ${dnf_ver:- 0} " -ge 5 ]; then
1262+ printf ' sudo dnf config-manager setopt %s.enabled=1\n' " $repo "
1263+ else
1264+ printf ' sudo dnf config-manager --set-enabled %s\n' " $repo "
1265+ fi
1266+ }
12211267
12221268 if [ " $PKG_MANAGER " = " dnf" ] || [ " $PKG_MANAGER " = " yum" ]; then
12231269 if [ " $PHPVM_LINUX_DISTRO " = " fedora" ]; then
1270+ major_minor=$( echo " $version " | cut -d. -f1,2)
12241271 phpvm_echo " "
12251272 phpvm_echo " PHP packages not found in default Fedora repositories."
12261273 phpvm_echo " To install PHP $version , you need to enable Remi's repository:"
@@ -1232,16 +1279,16 @@ suggest_repository_setup() {
12321279 phpvm_echo " sudo dnf install https://rpms.remirepo.net/fedora/remi-release-42.rpm"
12331280 fi
12341281 phpvm_echo " "
1235- phpvm_echo " # Enable the repository"
1236- phpvm_echo " sudo dnf config-manager --set-enabled remi"
1282+ phpvm_echo " # Enable the Remi repository"
1283+ _dnf_enable_repo_cmd " remi"
12371284 phpvm_echo " "
1238- phpvm_echo " # Enable specific PHP version repository"
1239- major_minor=$( echo " $version " | cut -d. -f1,2 | tr -d ' .' )
1240- phpvm_echo " sudo dnf config-manager --set-enabled remi-php$major_minor "
1285+ phpvm_echo " # Enable the PHP module stream for version $major_minor "
1286+ phpvm_echo " sudo dnf module enable php:remi-${major_minor} -y"
12411287 phpvm_echo " "
12421288 phpvm_echo " After setting up the repositories, try: phpvm install $version "
12431289
12441290 elif [ " $PHPVM_LINUX_DISTRO " = " rhel" ] || [ " $PHPVM_LINUX_DISTRO " = " rocky" ] || [ " $PHPVM_LINUX_DISTRO " = " almalinux" ] || [ " $PHPVM_LINUX_DISTRO " = " centos" ]; then
1291+ major_minor=$( echo " $version " | cut -d. -f1,2 | tr -d ' .' )
12451292 phpvm_echo " "
12461293 phpvm_echo " PHP packages not found in default RHEL/CentOS repositories."
12471294 phpvm_echo " To install PHP $version , you need to enable EPEL and Remi repositories:"
@@ -1258,9 +1305,8 @@ suggest_repository_setup() {
12581305 fi
12591306 phpvm_echo " "
12601307 phpvm_echo " # Enable the repositories"
1261- phpvm_echo " sudo dnf config-manager --set-enabled remi"
1262- major_minor=$( echo " $version " | cut -d. -f1,2 | tr -d ' .' )
1263- phpvm_echo " sudo dnf config-manager --set-enabled remi-php$major_minor "
1308+ _dnf_enable_repo_cmd " remi"
1309+ _dnf_enable_repo_cmd " remi-php${major_minor} "
12641310 phpvm_echo " "
12651311 phpvm_echo " After setting up the repositories, try: phpvm install $version "
12661312 fi
@@ -1612,16 +1658,28 @@ install_php_dnf() {
16121658
16131659 # Try to enable the module stream first
16141660 if command_exists dnf && dnf module list php > /dev/null 2>&1 ; then
1615- phpvm_echo " Enabling PHP:${normalized_version} module stream..."
1616- if ! run_with_sudo dnf module reset php -y 2> /dev/null; then
1617- phpvm_warn " Failed to reset PHP module"
1618- fi
1619- if ! run_with_sudo dnf module enable php:" ${normalized_version} " -y; then
1620- phpvm_warn " Failed to enable PHP:${normalized_version} module stream"
1661+ local php_stream
1662+ php_stream=$( dnf_resolve_php_stream " $normalized_version " )
1663+ if [ -z " $php_stream " ]; then
1664+ phpvm_warn " No php module stream found for PHP ${normalized_version} "
16211665 phpvm_warn " You may need Remi repository for this PHP version"
16221666 suggest_repository_setup " $version "
16231667 return " $PHPVM_EXIT_ERROR "
16241668 fi
1669+ phpvm_echo " Enabling php:${php_stream} module stream..."
1670+ if dnf_stream_enabled " $php_stream " ; then
1671+ phpvm_debug " Module stream php:${php_stream} is already enabled β skipping reset/enable"
1672+ else
1673+ if ! run_with_sudo dnf module reset php -y 2> /dev/null; then
1674+ phpvm_warn " Failed to reset PHP module"
1675+ fi
1676+ if ! run_with_sudo dnf module enable " php:${php_stream} " -y; then
1677+ phpvm_warn " Failed to enable php:${php_stream} module stream"
1678+ phpvm_warn " You may need Remi repository for this PHP version"
1679+ suggest_repository_setup " $version "
1680+ return " $PHPVM_EXIT_ERROR "
1681+ fi
1682+ fi
16251683 fi
16261684
16271685 # Install the base PHP package
@@ -2018,9 +2076,22 @@ switch_to_version_php() {
20182076 elif [ " $PKG_MANAGER " = " dnf" ]; then
20192077 # Try dnf module approach for RHEL/Fedora
20202078 if command_exists dnf && dnf module list php > /dev/null 2>&1 ; then
2021- phpvm_debug " Attempting to enable PHP $normalized_version module"
2022- if ! run_with_sudo dnf module enable php:" $normalized_version " -y; then
2023- phpvm_warn " Failed to enable PHP $normalized_version module."
2079+ local use_stream
2080+ use_stream=$( dnf_resolve_php_stream " $normalized_version " )
2081+ if [ -n " $use_stream " ]; then
2082+ phpvm_debug " Attempting to enable php:${use_stream} module"
2083+ if dnf_stream_enabled " $use_stream " ; then
2084+ phpvm_debug " Module stream php:${use_stream} already enabled"
2085+ else
2086+ if ! run_with_sudo dnf module reset php -y 2> /dev/null; then
2087+ phpvm_warn " Failed to reset PHP module"
2088+ fi
2089+ if ! run_with_sudo dnf module enable " php:${use_stream} " -y; then
2090+ phpvm_warn " Failed to enable php:${use_stream} module."
2091+ fi
2092+ fi
2093+ else
2094+ phpvm_warn " No php module stream found for PHP $normalized_version "
20242095 fi
20252096 fi
20262097 # After module enable, check if binary exists
0 commit comments