Skip to content

Commit 1aa59f3

Browse files
committed
refactor: enhance PHP installation process with intelligent repository detection and setup guidance for RHEL/Fedora systems
1 parent 7b486e1 commit 1aa59f3

File tree

3 files changed

+228
-10
lines changed

3 files changed

+228
-10
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,19 @@
22

33
## [v1.6.0] - 2025-09-15
44

5+
### Added
6+
7+
- **Smart repository detection:** Added intelligent detection of missing PHP repositories on RHEL/Fedora systems with automatic suggestions for enabling Remi's repository.
8+
- **Enhanced error messaging:** Implemented comprehensive error handling with actionable solutions when PHP packages are not found in default repositories.
9+
- **Repository setup guidance:** Added detailed step-by-step instructions for enabling EPEL and Remi repositories on Fedora, RHEL, Rocky Linux, AlmaLinux, and CentOS systems.
10+
511
### Changed
612

713
- **Consolidated GitHub Actions workflows:** Streamlined CI/CD from 7 separate workflow files down to 3 focused workflows, eliminating duplication while maintaining comprehensive test coverage.
814
- **Enhanced multi-distribution testing:** Expanded automated testing to cover 13 Linux distributions (Ubuntu, Debian, Fedora, Rocky Linux, AlmaLinux, Arch Linux, Alpine Linux) with 4 different package managers (apt, dnf, pacman, apk).
915
- **Improved cross-platform compatibility:** Fixed package installation issues for RHEL-family distributions (Rocky/Alma Linux) and Alpine Linux in CI environments.
1016
- **Streamlined workflow organization:** Reorganized tests into logical categories: syntax analysis, core functionality, PHP usage, multi-distribution compatibility, performance testing, and end-to-end integration.
17+
- **Intelligent PHP installation:** Enhanced PHP installation process to check package availability before attempting installation and provide specific guidance when packages are missing.
1118

1219
### Fixed
1320

README.MD

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,13 @@ PHP 8.1.13
4141
- Seamlessly switch between installed PHP versions.
4242
- Auto-switch PHP versions based on project `.phpvmrc`.
4343
- Supports macOS (via Homebrew) and Linux distributions including WSL.
44+
- **Smart repository detection** for RHEL/Fedora systems with automatic setup guidance.
45+
- **Enhanced error handling** with actionable solutions when PHP packages are missing.
46+
- **Intelligent package availability checking** before attempting installations.
4447
- Enhanced cross-platform compatibility with improved shell support.
4548
- Works with common shells (`bash`, `zsh`).
4649
- Comprehensive version commands (`phpvm version`, `phpvm --version`, `phpvm -v`).
4750
- Post-install validation with helpful warnings for missing binaries.
48-
- Improved error handling with detailed messages and suggestions.
4951
- Enhanced Homebrew integration with better link failure detection.
5052
- Informative, color-coded feedback with timestamps for logs.
5153
- Includes unit tests with BATS for automated testing.
@@ -108,6 +110,8 @@ To install a specific version of PHP:
108110
phpvm install 8.1
109111
```
110112

113+
**Smart Repository Detection**: On RHEL/Fedora systems, phpvm automatically detects if PHP packages are available in your current repositories. If not, it provides step-by-step instructions to enable the necessary repositories (like Remi's repository) before installation.
114+
111115
### Switching PHP Versions
112116

113117
To switch between installed versions:
@@ -196,6 +200,8 @@ export PATH="$PHPVM_DIR/bin:$PATH"
196200

197201
If you experience issues with `phpvm`, try the following:
198202

203+
### General Issues
204+
199205
- Run `phpvm test` to verify all functions are working correctly
200206
- Check the phpvm version with `phpvm version` or `phpvm --version`
201207
- Ensure your shell profile is sourcing `phpvm.sh`
@@ -209,6 +215,53 @@ If you experience issues with `phpvm`, try the following:
209215
- If you encounter Homebrew link issues on macOS, try manually relinking: `brew unlink [email protected] && brew link --force [email protected]`
210216
- Refer to the [Changelog](./CHANGELOG.md) for recent updates and fixes
211217

218+
### Repository Setup for RHEL/Fedora Systems
219+
220+
If you encounter "PHP packages not found" errors on RHEL-family distributions, phpvm will automatically provide setup instructions. You can also manually enable the required repositories:
221+
222+
#### Fedora Systems
223+
224+
```bash
225+
# Install Remi's repository
226+
sudo dnf install https://rpms.remirepo.net/fedora/remi-release-$(rpm -E %fedora).rpm
227+
228+
# Enable the repository
229+
sudo dnf config-manager --set-enabled remi
230+
231+
# Enable specific PHP version (example for PHP 8.3)
232+
sudo dnf config-manager --set-enabled remi-php83
233+
```
234+
235+
#### RHEL/Rocky/AlmaLinux/CentOS Systems
236+
237+
```bash
238+
# Install EPEL repository
239+
sudo dnf install epel-release
240+
241+
# Install Remi's repository
242+
sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-$(rpm -E %rhel).rpm
243+
244+
# Enable the repositories
245+
sudo dnf config-manager --set-enabled remi
246+
sudo dnf config-manager --set-enabled remi-php83 # for PHP 8.3
247+
```
248+
249+
#### Alternative: Use Homebrew on Linux
250+
251+
If you prefer to avoid repository management, you can install Homebrew on Linux:
252+
253+
```bash
254+
# Install Homebrew on Linux
255+
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
256+
257+
# Add to your shell profile
258+
echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' >> ~/.bashrc
259+
source ~/.bashrc
260+
261+
# Now phpvm will use Homebrew instead of dnf/yum
262+
phpvm install 8.3
263+
```
264+
212265
## Development & Testing
213266

214267
phpvm features comprehensive testing across multiple platforms and scenarios. The project includes extensive GitHub Actions workflows that test every aspect of the script.

phpvm.sh

Lines changed: 167 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
# phpvm - A PHP Version Manager for macOS and Linux
44
# Author: Jerome Thayananthajothy ([email protected])
5-
# Version: 1.5.0
5+
# Version: 1.6.0
66

7-
PHPVM_VERSION="1.5.0"
7+
PHPVM_VERSION="1.6.0"
88

99
# Define a debug mode for testing
1010
if [ "${BATS_TEST_FILENAME:-}" != "" ]; then
@@ -264,6 +264,109 @@ validate_php_version() {
264264
return 1
265265
}
266266

267+
# Check if Remi repository is available/enabled for RHEL/Fedora systems
268+
check_remi_repository() {
269+
# Check if Remi repository is installed
270+
if command -v dnf >/dev/null 2>&1; then
271+
dnf repolist enabled 2>/dev/null | grep -q remi
272+
elif command -v yum >/dev/null 2>&1; then
273+
yum repolist enabled 2>/dev/null | grep -q remi
274+
else
275+
return 1
276+
fi
277+
}
278+
279+
# Detect if PHP packages are available in current repositories
280+
detect_php_availability() {
281+
version="$1"
282+
283+
case "$PKG_MANAGER" in
284+
dnf)
285+
if dnf search "php$version" 2>/dev/null | grep -q "php$version"; then
286+
return 0
287+
elif dnf search "php" 2>/dev/null | grep -q "php[0-9]"; then
288+
# Some PHP packages exist, but not the requested version
289+
return 2
290+
else
291+
# No PHP packages found at all
292+
return 1
293+
fi
294+
;;
295+
yum)
296+
if yum search "php$version" 2>/dev/null | grep -q "php$version"; then
297+
return 0
298+
elif yum search "php" 2>/dev/null | grep -q "php[0-9]"; then
299+
return 2
300+
else
301+
return 1
302+
fi
303+
;;
304+
apt)
305+
if apt-cache search "php$version" 2>/dev/null | grep -q "php$version"; then
306+
return 0
307+
else
308+
return 1
309+
fi
310+
;;
311+
*)
312+
# For other package managers, assume available
313+
return 0
314+
;;
315+
esac
316+
}
317+
318+
# Provide repository setup suggestions for RHEL/Fedora systems
319+
suggest_repository_setup() {
320+
version="$1"
321+
322+
if [ "$PKG_MANAGER" = "dnf" ] || [ "$PKG_MANAGER" = "yum" ]; then
323+
if [ "$LINUX_DISTRO" = "fedora" ]; then
324+
phpvm_echo ""
325+
phpvm_echo "PHP packages not found in default Fedora repositories."
326+
phpvm_echo "To install PHP $version, you need to enable Remi's repository:"
327+
phpvm_echo ""
328+
phpvm_echo " # Install Remi's repository"
329+
if [ -n "$LINUX_VERSION" ]; then
330+
phpvm_echo " sudo dnf install https://rpms.remirepo.net/fedora/remi-release-$LINUX_VERSION.rpm"
331+
else
332+
phpvm_echo " sudo dnf install https://rpms.remirepo.net/fedora/remi-release-42.rpm"
333+
fi
334+
phpvm_echo ""
335+
phpvm_echo " # Enable the repository"
336+
phpvm_echo " sudo dnf config-manager --set-enabled remi"
337+
phpvm_echo ""
338+
phpvm_echo " # Enable specific PHP version repository"
339+
major_minor=$(echo "$version" | cut -d. -f1,2 | tr -d '.')
340+
phpvm_echo " sudo dnf config-manager --set-enabled remi-php$major_minor"
341+
phpvm_echo ""
342+
phpvm_echo "After setting up the repository, try: phpvm install $version"
343+
344+
elif [ "$LINUX_DISTRO" = "rhel" ] || [ "$LINUX_DISTRO" = "rocky" ] || [ "$LINUX_DISTRO" = "almalinux" ] || [ "$LINUX_DISTRO" = "centos" ]; then
345+
phpvm_echo ""
346+
phpvm_echo "PHP packages not found in default RHEL/CentOS repositories."
347+
phpvm_echo "To install PHP $version, you need to enable EPEL and Remi repositories:"
348+
phpvm_echo ""
349+
phpvm_echo " # Install EPEL repository"
350+
phpvm_echo " sudo dnf install epel-release"
351+
phpvm_echo ""
352+
phpvm_echo " # Install Remi's repository"
353+
if [ -n "$LINUX_VERSION" ]; then
354+
major_version=$(echo "$LINUX_VERSION" | cut -d. -f1)
355+
phpvm_echo " sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-$major_version.rpm"
356+
else
357+
phpvm_echo " sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-9.rpm"
358+
fi
359+
phpvm_echo ""
360+
phpvm_echo " # Enable the repositories"
361+
phpvm_echo " sudo dnf config-manager --set-enabled remi"
362+
major_minor=$(echo "$version" | cut -d. -f1,2 | tr -d '.')
363+
phpvm_echo " sudo dnf config-manager --set-enabled remi-php$major_minor"
364+
phpvm_echo ""
365+
phpvm_echo "After setting up the repositories, try: phpvm install $version"
366+
fi
367+
fi
368+
}
369+
267370
# Install PHP using the detected package manager
268371
install_php() {
269372
version="$1"
@@ -357,18 +460,51 @@ install_php() {
357460
;;
358461
dnf)
359462
# Fedora/RHEL 8+ with dnf
463+
# First, check if PHP packages are available
464+
detect_php_availability "$version"
465+
availability_status=$?
466+
467+
if [ $availability_status -eq 1 ]; then
468+
# No PHP packages found - suggest repository setup
469+
phpvm_err "PHP packages not found in current repositories."
470+
suggest_repository_setup "$version"
471+
return 1
472+
elif [ $availability_status -eq 2 ]; then
473+
# Some PHP packages exist, but not the requested version
474+
phpvm_warn "PHP $version not found, but other PHP versions are available."
475+
phpvm_echo "Available PHP packages:"
476+
dnf search php 2>/dev/null | grep "^php[0-9]" | head -5
477+
phpvm_echo ""
478+
if ! check_remi_repository; then
479+
phpvm_echo "For more PHP versions, consider enabling Remi's repository:"
480+
suggest_repository_setup "$version"
481+
fi
482+
return 1
483+
fi
484+
485+
# Packages are available, proceed with installation
360486
if [ "$LINUX_DISTRO" = "fedora" ]; then
361487
# Fedora uses different PHP packages
362488
if ! run_with_sudo dnf install -y php"$version" php"$version"-cli; then
363-
phpvm_err "Failed to install PHP $version. Package php$version may not exist."
364-
phpvm_warn "Check available versions with: dnf search php"
489+
phpvm_err "Failed to install PHP $version."
490+
# Check if Remi repository might help
491+
if ! check_remi_repository; then
492+
phpvm_echo ""
493+
phpvm_echo "If the package wasn't found, you might need Remi's repository:"
494+
suggest_repository_setup "$version"
495+
fi
365496
return 1
366497
fi
367498
else
368499
# RHEL/CentOS with dnf
369500
if ! run_with_sudo dnf install -y php"$version"; then
370-
phpvm_err "Failed to install PHP $version. Package php$version may not exist."
371-
phpvm_warn "You may need to enable EPEL or Remi repository"
501+
phpvm_err "Failed to install PHP $version."
502+
# Check if repositories might help
503+
if ! check_remi_repository; then
504+
phpvm_echo ""
505+
phpvm_echo "You may need to enable additional repositories:"
506+
suggest_repository_setup "$version"
507+
fi
372508
return 1
373509
fi
374510
fi
@@ -382,10 +518,32 @@ install_php() {
382518
fi
383519
fi
384520

521+
# Check PHP availability first
522+
detect_php_availability "$version"
523+
availability_status=$?
524+
525+
if [ $availability_status -eq 1 ]; then
526+
# No PHP packages found - suggest repository setup
527+
phpvm_err "PHP packages not found in current repositories."
528+
suggest_repository_setup "$version"
529+
return 1
530+
elif [ $availability_status -eq 2 ]; then
531+
# Some PHP packages exist, but not the requested version
532+
phpvm_warn "PHP $version not found, but other PHP versions are available."
533+
if ! check_remi_repository; then
534+
phpvm_echo "For more PHP versions, consider enabling Remi's repository:"
535+
suggest_repository_setup "$version"
536+
fi
537+
return 1
538+
fi
539+
385540
if ! run_with_sudo yum install -y php"$version"; then
386-
phpvm_err "Failed to install PHP $version. Package php$version may not exist."
387-
phpvm_warn "Consider enabling EPEL: sudo yum install epel-release"
388-
phpvm_warn "Consider enabling Remi: sudo yum install https://rpms.remirepo.net/enterprise/remi-release-7.rpm"
541+
phpvm_err "Failed to install PHP $version."
542+
if ! check_remi_repository; then
543+
phpvm_echo ""
544+
phpvm_echo "You may need to enable additional repositories:"
545+
suggest_repository_setup "$version"
546+
fi
389547
return 1
390548
fi
391549
;;

0 commit comments

Comments
 (0)