phpvm
is a lightweight PHP Version Manager that allows you to easily install, switch between, and manage multiple PHP versions via the command line.
Example:
$ phpvm use 8.2
Now using PHP v8.2.10
$ php -v
PHP 8.2.10
$ phpvm use 8.1
Now using PHP v8.1.13
$ php -v
PHP 8.1.13
- Install and manage multiple PHP versions.
- Seamlessly switch between installed PHP versions.
- Auto-switch PHP versions based on project
.phpvmrc
. - Supports macOS (via Homebrew) and Linux distributions.
- Works with common shells (
bash
,zsh
). - Improved error handling and informative, color-coded feedback.
- Includes unit tests with BATS for automated testing.
To install or update phpvm, run one of the following commands:
curl -o- https://raw.githubusercontent.com/Thavarshan/phpvm/main/install.sh | bash
wget -qO- https://raw.githubusercontent.com/Thavarshan/phpvm/main/install.sh | bash
This script will download and set up phpvm
in ~/.phpvm
and automatically update your shell profile (~/.bashrc
, ~/.zshrc
, or ~/.profile
) with the following lines:
export PHPVM_DIR="$HOME/.phpvm"
source "$PHPVM_DIR/phpvm.sh"
Run the following command:
command -v phpvm
If the installation was successful, it should output the path to phpvm
.
To install a specific version of PHP:
phpvm install 8.1
To switch between installed versions:
phpvm use 8.0
Verify the active version with:
php -v
Create a .phpvmrc
file in your project directory to specify the desired PHP version:
echo "8.1" > .phpvmrc
When you navigate to that project directory, phpvm
will automatically switch to PHP 8.1.
To uninstall a specific PHP version:
phpvm uninstall 7.4
To list installed PHP versions:
phpvm list
To completely remove phpvm
, run:
rm -rf ~/.phpvm
Then remove the following lines from your shell profile (~/.bashrc
, ~/.zshrc
, or ~/.profile
):
export PHPVM_DIR="$HOME/.phpvm"
source "$PHPVM_DIR/phpvm.sh"
If you experience issues with phpvm
, try the following:
- Ensure your shell profile is sourcing
phpvm.sh
. - Restart your terminal after installing or updating.
- Verify that Homebrew is installed (for macOS users).
- Check for permission issues during the installation or PHP version switching process.
- Refer to the Changelog for recent updates and fixes.
- This project includes a set of BATS unit tests located in the repository (e.g.,
test_phpvm.bats
). - Contributions, bug reports, and feature requests are welcome.
phpvm
is maintained by Jerome Thayananthajothy.
This project is licensed under the MIT License. See LICENSE for details.
phpvm
is provided as-is without any warranties. Use it at your own risk.