sphp is a simple yet powerful Bash script that allows you to easily switch between different PHP versions installed via Homebrew on your macOS.
- Effortless Switching: Quickly change your active PHP version with a single command.
- Version Management: Supports
php@7.4,php@8.1,php@8.2,php@8.3, andphp@8.4. - Intelligent Installation: Prompts to install a PHP version if it's not already on your system.
- Current Version Check: See which PHP version is currently active.
- List Installed Versions: Get a clear overview of all PHP versions you have installed through Homebrew.
- User-Friendly: Provides clear usage instructions and prompts for a smooth experience.
- Homebrew: This script relies on Homebrew for managing PHP installations. If you don't have it, install it from brew.sh.
curl -L https://raw.githubusercontent.com/Shubhamc4/sphp.sh/refs/heads/main/sphp.sh > /opt/homebrew/bin/sphp
chmod +x /opt/homebrew/bin/sphpcurl -L https://raw.githubusercontent.com/Shubhamc4/sphp.sh/refs/heads/main/sphp.sh > /usr/local/bin/sphp
chmod +x /usr/local/bin/sphpsphp <version>Replace <version> with the desired PHP version. You can specify the version in two ways:
- Short form:
sphp 8.2(forphp@8.2) - Full form:
sphp php@8.3
- Switch to PHP 8.4:
sphp 8.4
- Switch to PHP 7.4 (using full name):
sphp php@7.4
- Interactive mode (if no argument is provided):
sphp # 👉 Enter PHP version (e.g. 8.2 or php@8.2):
-l,--list: List all PHP versions installed via Homebrew.sphp -l
-c,--current: Show the currently active PHP version.sphp -c
-v,--version: Display the script's version information.sphp -v
-h,--help: Show the usage instructions and available options.sphp -h
The sphp script automates the process of switching PHP versions by:
- Unlinking all currently linked Homebrew PHP versions.
- Linking the specified PHP version, making it the active one in your
PATH. - If the target PHP version isn't installed, it will prompt you to install it using Homebrew.
- If you encounter issues, ensure Homebrew is up-to-date and healthy:
brew update brew doctor
- If a specific PHP version fails to link, try linking it manually:
(Replace
brew link --overwrite --force php@8.x
php@8.xwith the version you're trying to link)
Shubham Chaudhary