https://github.com/devhardiyanto/phpvm
https://github.com/devhardiyanto/phpvm
Last synced: 30 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/devhardiyanto/phpvm
- Owner: devhardiyanto
- Created: 2026-05-10T03:21:38.000Z (about 2 months ago)
- Default Branch: main
- Last Pushed: 2026-06-09T08:43:04.000Z (30 days ago)
- Last Synced: 2026-06-09T09:24:00.652Z (30 days ago)
- Language: PowerShell
- Size: 60.5 KB
- Stars: 2
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# phpvm — PHP Version Manager
Install and switch PHP versions on **Windows** (CMD + PowerShell) and **Linux** (bash/zsh), without admin rights.
---
## Installation
### Windows
```powershell
# Download both files (phpvm.ps1 + install.ps1) to the same folder, then:
.\install.ps1
```
Restart your terminal. No admin required.
### Linux
```bash
curl -fsSL https://raw.githubusercontent.com/devhardiyanto/phpvm/main/linux/install.sh | bash
source ~/.bashrc
```
Or manually:
```bash
git clone https://github.com/devhardiyanto/phpvm.git ~/.phpvm-src
source ~/.phpvm-src/linux/phpvm.sh
```
---
## Usage
### Version Management
```bash
phpvm install 8.3.0 # install a specific PHP version
phpvm install 8.3 # install latest 8.3.x patch (auto-resolves)
phpvm install 7.3 # works for older lines (7.x, 5.x)
phpvm use 8.3.0 # switch active version
phpvm list # list installed versions
phpvm current # show active version
phpvm uninstall 8.1.29 # remove a version
phpvm which # path to active php binary
phpvm ini # open php.ini in editor
```
### Auto-Switch with `.phpvmrc` (Windows)
Drop a `.phpvmrc` file in your project root containing the PHP version you want:
```bash
echo "8.3" > .phpvmrc
```
Then run `phpvm auto` from anywhere in the project — phpvm walks up to find the nearest `.phpvmrc` and prepends that version to your shell `PATH` (session only, your global `phpvm use` is untouched).
For hands-off switching, install the PowerShell prompt hook:
```powershell
phpvm hook install # adds a snippet to $PROFILE
# restart PowerShell, then `cd` between projects - phpvm auto-switches per directory
phpvm hook status # check whether the hook is installed
phpvm hook uninstall # remove the hook
```
`.phpvmrc` accepts a full semver (`8.3.0`), a major.minor (`8.3` — picks the highest installed patch), or a leading `v` (`v8.3.0`). Lines starting with `#` are comments. If the version is not installed locally, phpvm warns but never auto-installs.
### Extension Management
```bash
# List / inspect
phpvm ext list # all bundled extensions (ON/OFF)
phpvm ext loaded # currently loaded (php -m)
phpvm ext info redis # details about an extension
# Enable/disable bundled extensions (edit php.ini)
phpvm ext enable mbstring
phpvm ext enable pdo_mysql
phpvm ext enable curl
phpvm ext enable zip
phpvm ext disable pdo_sqlite
# Install PECL extensions
phpvm ext install redis
phpvm ext install imagick
phpvm ext install mongodb
phpvm ext install mongodb 1.17.0 # specific version
# XDebug (Windows: from xdebug.org | Linux: via PECL)
phpvm ext install xdebug
```
---
## How It Works
### Windows
- Downloads PHP binaries from [windows.php.net](https://windows.php.net/downloads/releases/)
- Stores versions in `%USERPROFILE%\.phpvm\versions\\`
- Switches via a **directory junction** (`mklink /J`) — no admin needed
- Extensions installed from [windows.php.net PECL](https://windows.php.net/downloads/pecl/releases/)
- XDebug fetched directly from [xdebug.org](https://xdebug.org/files/)
### Linux
- Builds PHP from source ([php.net](https://www.php.net/distributions/))
- Stores versions in `~/.phpvm/versions//`
- Switches via symlink (`~/.phpvm/current`) prepended to `$PATH`
- Extensions installed via `pecl`, enabled via per-version `conf.d/` drop-ins
---
## Linux: Build Dependencies
Run `phpvm deps` to print the install command for your distro.
**Ubuntu / Debian:**
```bash
sudo apt-get install -y \
build-essential autoconf bison re2c pkg-config \
libxml2-dev libsqlite3-dev libssl-dev libcurl4-openssl-dev \
libonig-dev libzip-dev zlib1g-dev libreadline-dev \
libpng-dev libjpeg-dev libwebp-dev libfreetype6-dev \
libgmp-dev libmysqlclient-dev libpq-dev
```
---
## Repository Structure
```
phpvm/
├── windows/
│ ├── phpvm.ps1 # main script
│ └── install.ps1 # installer
├── linux/
│ ├── phpvm.sh # main script (sourced in .bashrc)
│ └── install.sh # curl installer
└── README.md
```
## Install Directory Structure
```
~/.phpvm/
├── versions/
│ ├── 8.3.0/ # Windows: php.exe lives here
│ │ # Linux: bin/php lives here
│ └── 8.1.29/
├── current -> versions/8.3.0 (junction on Windows, symlink on Linux)
├── cache/ # Linux: cached source tarballs
├── bin/ # Windows: phpvm.cmd + phpvm.ps1 shim
├── phpvm.ps1 # Windows: main script
└── phpvm.sh # Linux: main script (sourced in .bashrc)
```
---
## Environment Variables
| Variable | Default | Description |
|---|---|---|
| `PHPVM_DIR` | `~/.phpvm` | phpvm home directory |
| `EDITOR` | `nano` | Editor used by `phpvm ini` (Linux) |
| `PHPVM_SKIP_HASH` | _unset_ | When set to `1`, skip SHA-256 verification on Windows installs (use for content-rewriting corporate proxies) |
| `PHPVM_NO_UPDATE_CHECK` | _unset_ | When set, skip the daily phpvm update check |
| `PHPVM_AUTO_ACTIVE` | _unset_ | Internal: tracks the version currently pinned by `phpvm auto` in the current shell |
---
## Compatibility
| Platform | Shell | Status |
|---|---|---|
| Windows 10/11 | CMD | ✅ |
| Windows 10/11 | PowerShell 5+ | ✅ |
| Ubuntu 20.04+ | bash / zsh | ✅ |
| Debian 11+ | bash / zsh | ✅ |
| Fedora / RHEL | bash / zsh | ✅ |
| Arch Linux | bash / zsh | ✅ |
---
## License
MIT