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
[email protected]
,[email protected]
,[email protected]
,[email protected]
, and[email protected]
. - 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/sphp
curl -L https://raw.githubusercontent.com/Shubhamc4/sphp.sh/refs/heads/main/sphp.sh > /usr/local/bin/sphp
chmod +x /usr/local/bin/sphp
sphp <version>
Replace <version>
with the desired PHP version. You can specify the version in two ways:
- Short form:
sphp 8.2
(for[email protected]
) - Full form:
sphp [email protected]
- Switch to PHP 8.4:
sphp 8.4
- Switch to PHP 7.4 (using full name):
sphp [email protected]
- Interactive mode (if no argument is provided):
sphp # 👉 Enter PHP version (e.g. 8.2 or [email protected]):
-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 [email protected]
[email protected]
with the version you're trying to link)
Shubham Chaudhary