A simple and elegant PHP version manager for Linux, inspired by nvm (Node Version Manager).
Easily switch between multiple PHP versions with a single command!
- π Quick Version Switching - Switch PHP versions with a single command
- π List Installed Versions - See all available PHP versions at a glance
- π List Remote Versions - See all PHP versions available to install
- π Detailed PHP Info - View memory limits, config paths, timezone, and more
- π§© Extension Management - List, compare, and install PHP extensions
- π¨ Colored Output - Beautiful, easy-to-read terminal output
- β¨οΈ Tab Completion - Auto-complete version numbers and commands
- π§ Tool Switching - Automatically switches related tools (phpize, phar, php-config)
- π Support Status - Shows Active Support, Security Only, and EOL status
- Linux (Ubuntu/Debian-based distributions)
- Bash shell
- Multiple PHP versions installed via
apt(e.g., from OndΕej SurΓ½'s PPA) sudoprivileges (for switching PHP versions)
# Add the PHP repository
sudo add-apt-repository ppa:ondrej/php
sudo apt update
# Install desired PHP versions
sudo apt install php7.4 php8.0 php8.1 php8.2 php8.3 php8.4
# Install common extensions (optional)
sudo apt install php8.3-{cli,fpm,mysql,xml,curl,mbstring,zip,gd,bcmath}curl -o ~/.php-switch https://raw.githubusercontent.com/alanshijo/php-version-manager/main/php-switch.sh && echo 'source ~/.php-switch' >> ~/.bashrc && source ~/.bashrc-
Download the script:
curl -o ~/.php-switch https://raw.githubusercontent.com/alanshijo/php-version-manager/main/php-switch.shOr clone the repository:
git clone https://github.com/alanshijo/php-version-manager.git cp php-switch/php-switch.sh ~/.php-switch -
Add to your shell configuration:
For Bash (
~/.bashrc):echo 'source ~/.php-switch' >> ~/.bashrc
For Zsh (
~/.zshrc):echo 'source ~/.php-switch' >> ~/.zshrc
-
Reload your shell:
source ~/.bashrc # or source ~/.zshrc
-
Verify installation:
php-switch --help
# Switch to PHP 8.3
php-switch 8.3
# Alternative syntax
php-use 8.3
# Also accepts 'php' prefix
php-switch php7.4php-list
# Output:
# Installed PHP versions:
#
# 7.4
# 8.2
# βΊ 8.3 (current)
# 8.4php-switch --current
# or
php-switch -cphp-info
# Output:
# βββββββββββββββββββββββββββββββββββββββββββββ
# β PHP Information β
# βββββββββββββββββββββββββββββββββββββββββββββ
#
# Version: 8.3
# Binary: /usr/bin/php
# Config File: /etc/php/8.3/cli/php.ini
# Memory Limit: -1
# Max Execution: 0s
# Upload Max: 2M
# Post Max: 8M
# Timezone: UTC
# Composer: 2.8.6# Show all supported PHP versions
php-ls-remote
# Output:
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# β Available PHP Versions (Remote) β
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
#
# VERSION RELEASE STATUS SUPPORT
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# 8.5 2025-11-20 Active Support until 2027-12-31 (Latest)
# β 8.4 2024-11-21 Active Support until 2026-12-31 (current)
# β 8.3 2023-11-23 Security Only until 2027-12-31
# β 8.2 2022-12-08 Security Only until 2026-12-31
# 8.1 2021-11-25 Security Only until 2025-12-31
# Show only LTS/supported versions
php-ls-remote --lts
# Show all versions including EOL
php-ls-remote --all
# Filter by major version
php-ls-remote 8php-latest
# Fetches latest stable releases from php.net API# List extensions for current PHP version
php-extensions
# List extensions for a specific version
php-extensions 8.1php-compare 7.4 8.3
# Shows extensions unique to each version# List available packages for current PHP version
php-modules
# Search for specific packages
php-modules mysql
php-modules curl# Install an extension for current PHP version
php-install curl
php-install mysql
php-install gd| Command | Alias | Description |
|---|---|---|
php-switch <version> |
php-use <version> |
Switch to specified PHP version |
php-switch --list |
php-switch -l |
List all installed versions |
php-switch --current |
php-switch -c |
Show current PHP version |
php-switch --info |
php-switch -i |
Show detailed PHP information |
php-switch --help |
php-switch -h |
Show help message |
php-list |
- | List installed versions with current highlighted |
php-ls-remote |
- | List all available PHP versions (like nvm ls-remote) |
php-ls-remote --lts |
- | List only supported versions |
php-ls-remote --all |
- | List all versions including EOL |
php-ls-remote <ver> |
- | Filter by version (e.g., 8, 8.3) |
php-latest |
- | Fetch latest releases from php.net |
php-info |
- | Display detailed PHP configuration |
php-extensions [ver] |
- | List extensions (optionally for specific version) |
php-modules [keyword] |
- | Search available apt packages |
php-install <ext> |
- | Install extension for current version |
php-compare <v1> <v2> |
- | Compare extensions between two versions |
PHP Switch uses Ubuntu/Debian's update-alternatives system to manage PHP versions. When you switch versions, it updates the symbolic links for:
php- Main PHP binaryphar- PHP Archive toolphar.phar- PHP Archive tool (alternative)phpize- PHP extension build toolphp-config- PHP build configurationphpdbg- PHP debugger
If your PHP binaries are installed in a different location, you can modify the script:
# Edit ~/.php-switch and change this line:
ls -1 /usr/bin/php[0-9]* 2>/dev/null
# To your custom path:
ls -1 /custom/path/php[0-9]* 2>/dev/nullTo disable colored output, add this before sourcing the script:
export PHP_SWITCH_NO_COLOR=1
source ~/.php-switchMake sure the PHP version is installed:
ls /usr/bin/php*If not installed, add OndΕej's PPA and install:
sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt install php8.3The script requires sudo to modify system alternatives. Make sure your user has sudo privileges.
Reload your shell configuration:
source ~/.bashrcOr restart your terminal.
This script only changes the CLI PHP version. For web servers, you need to:
# For Apache
sudo a2dismod php7.4
sudo a2enmod php8.3
sudo systemctl restart apache2
# For Nginx with PHP-FPM
sudo systemctl stop php7.4-fpm
sudo systemctl start php8.3-fpm
# Update your nginx config to use the new FPM socketContributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Inspired by nvm (Node Version Manager)
- Thanks to OndΕej SurΓ½ for maintaining the PHP PPA
If you encounter any issues or have questions, please open an issue on GitHub.
Happy PHP switching! π