Skip to content

Commit e3a3346

Browse files
authored
Merge pull request #19 from Its-Satyajit/is-branch-1
feat(php): Add system default PHP switching functionality
2 parents 40539f3 + 928c557 commit e3a3346

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,24 @@ Replace `<version>` with the desired shorthand.
137137

138138
### Troubleshooting
139139

140+
![](assets/20240716_210340_switch_10.png)
141+
142+
#### Revert to System PHP
143+
144+
To switch back to the default PHP version installed by your system package manager (e.g., `pacman`):
145+
146+
```bash
147+
phpv system
148+
```
149+
150+
This removes the overrides created by `phpv`.
151+
152+
To use a specific PHP version again, simply run:
153+
154+
```bash
155+
phpv <version>
156+
```
157+
140158
### Updates
141159

142160
To update `phpv` to the latest version from the repository:

phpv

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,22 @@ install_c_client() {
113113
fi
114114
}
115115

116+
# Function to switch to system default PHP (remove symlinks)
117+
switch_to_system() {
118+
print_info "Reverting to system default PHP..."
119+
120+
# List of binaries to unlink (must match create_symlinks)
121+
local binaries=(php php-cgi php-config phpize php-fpm phpdbg)
122+
123+
for bin in "${binaries[@]}"; do
124+
rm -f "${HOME}/bin/${bin}"
125+
done
126+
127+
print_success "Symlinks removed. You are now using the system default PHP."
128+
print_info "Verifying version..."
129+
php -v
130+
}
131+
116132
# Function to self-update phpv
117133
self_update() {
118134
print_info "Checking for updates..."
@@ -332,6 +348,10 @@ while [[ $# -gt 0 ]]; do
332348
action="self_update"
333349
shift
334350
;;
351+
system)
352+
action="system"
353+
shift
354+
;;
335355
-*)
336356
print_error "Unknown magic spell: $1"
337357
exit 1
@@ -356,6 +376,7 @@ if [ -z "$action" ]; then
356376
print_info " $0 -i <version> --nocheck : Skip tests during build"
357377
print_info " $0 -e <extension> <version> : Install PHP extension (e.g., 'imagick 81')"
358378
print_info " $0 <version> : Switch to PHP version"
379+
print_info " $0 system : Revert to system default PHP"
359380
print_info " $0 -u, --self-update : Update phpv to the latest version"
360381
print_info " $0 -v : Show version"
361382
exit 1
@@ -374,6 +395,9 @@ install_extension)
374395
self_update)
375396
self_update
376397
;;
398+
system)
399+
switch_to_system
400+
;;
377401
switch)
378402
switch_php_version "$version"
379403
;;

0 commit comments

Comments
 (0)