Skip to content

Shubhamc4/sphp.sh

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

sphp: Switch between installed PHP versions using Homebrew

sphp is a simple yet powerful Bash script that allows you to easily switch between different PHP versions installed via Homebrew on your macOS.

Features

  • 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.

Requirements

  • Homebrew: This script relies on Homebrew for managing PHP installations. If you don't have it, install it from brew.sh.

Installation

Apple Silicon Macs:

curl -L https://raw.githubusercontent.com/Shubhamc4/sphp.sh/refs/heads/main/sphp.sh > /opt/homebrew/bin/sphp
chmod +x /opt/homebrew/bin/sphp

Intel Macs:

curl -L https://raw.githubusercontent.com/Shubhamc4/sphp.sh/refs/heads/main/sphp.sh > /usr/local/bin/sphp
chmod +x /usr/local/bin/sphp

Usage

sphp <version>

Replace <version> with the desired PHP version. You can specify the version in two ways:

Examples

  • Switch to PHP 8.4:
    sphp 8.4
  • Switch to PHP 7.4 (using full name):
  • Interactive mode (if no argument is provided):
    sphp
    # 👉 Enter PHP version (e.g. 8.2 or [email protected]):

Options

  • -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

How it Works

The sphp script automates the process of switching PHP versions by:

  1. Unlinking all currently linked Homebrew PHP versions.
  2. Linking the specified PHP version, making it the active one in your PATH.
  3. If the target PHP version isn't installed, it will prompt you to install it using Homebrew.

Troubleshooting

  • 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:
    brew link --overwrite --force [email protected]
    (Replace [email protected] with the version you're trying to link)

Author

Shubham Chaudhary

About

Switch between installed PHP versions using Homebrew on macOS/Linux

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages