Download the PHP package rawdreeg/phpswitcher without Composer
On this page you can find all versions of the php package rawdreeg/phpswitcher. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rawdreeg/phpswitcher
More information about rawdreeg/phpswitcher
Files in rawdreeg/phpswitcher
Package phpswitcher
Short Description A simple CLI tool to manage multiple PHP versions on macOS using Homebrew. Linux and Windows support planned.
License MIT
Informations about the package phpswitcher
PHP Switcher
A simple CLI tool to manage multiple PHP versions on macOS and Linux.
Features
- Install specific PHP versions (via Homebrew for macOS, or APT for Linux).
- Switch the active PHP version.
- List all installed PHP versions.
- Auto-detect required version from
.php-version
orcomposer.json
. - Automatic version switching when you change directories.
Prerequisites
- macOS: Requires Homebrew for installing and managing PHP versions.
- Linux (Debian/Ubuntu): Requires
apt
and thesoftware-properties-common
package.sudo
is required for installing and switching versions.
Installation
Run the following command in your terminal to download and execute the installation script:
This will install phpswitcher
to $HOME/.phpswitcher
and add it to your shell's profile file (e.g., .zshrc
, .bashrc
).
After installation, open a new terminal session or run source ~/.zshrc
(or the equivalent for your shell) and verify with:
Usage
List installed PHP versions:
Shows all available PHP versions and highlights the one that is currently active.
Install a PHP version:
If you are in a directory containing a composer.json
file with a PHP requirement, you can omit the <version>
argument to automatically detect and install the required X.Y
version.
Switch active PHP version:
If you are in a directory containing a composer.json
file with a PHP requirement (require.php
or config.platform.php
), you can omit the <version>
argument, and phpswitcher
will attempt to detect and use the appropriate X.Y
version.
Show Version:
Self-Update:
This will fetch and install the latest version of phpswitcher
from GitHub.
Check active PHP version (after switching):
Automatic Version Switching
phpswitcher
supports automatic version switching when you change directories. This is achieved by hooking into your shell's prompt.
How it Works
- When you
cd
into a new directory,phpswitcher
looks for a.php-version
file in the current directory or any parent directory. - If a
.php-version
file is found, it reads the required version from it. - If the required version is not the currently active version,
phpswitcher
automatically runsphpswitcher use
to switch to the correct version.
Usage
To use this feature, simply create a file named .php-version
in the root of your project and put the desired PHP version number in it.
Now, whenever you cd
into this directory (or any subdirectory), phpswitcher
will ensure that PHP 8.1 is activated automatically.
This feature is enabled by default during the installation process, which adds a sourcing line to your shell's profile file (.bashrc
or .zshrc
).
Development
- Clone the repository:
git clone https://github.com/rawdreeg/phpswitcher.git
- Navigate into the project directory:
cd phpswitcher
. -
The main script is
bin/phpswitcher
. You can run it directly for testing: -
To create a release artifact, run the build script:
This will create a
phpswitcher.tar.gz
in the root directory.
Contributing
Contributions are welcome! Please feel free to open issues or submit pull requests.
License
MIT License