WordPress
WP-CLI Installation
Command-line interface for WordPress
Using Composer
Install WP-CLI globally
Terminal
composer global require wp-cli/wp-cli-bundle
You then have to use only Unix-like shell on Windows.
WP-CLI will only work in Git Bash or Windows Subsystem for Linux (WSL).
Terminal won't recognize wp as a command.
WP-CLI will only work in Git Bash or Windows Subsystem for Linux (WSL).
Terminal won't recognize wp as a command.
Check installation
Git bash
wp --info
Install dotenv package
Package that generates .env files for each environment.
Essential for using the wp dotenv command.
Terminal
cd %USERPROFILE%\.wp-cli\packages
composer require aaemnnosttv/wp-cli-dotenv-command:dev-master
Using the PHAR file
Powershell
# Create a folder for WP-CLI
mkdir C:\wp-cli
# Download wp-cli.phar
Invoke-WebRequest -Uri https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar -OutFile C:\wp-cli\wp-cli.phar
# Create a wp.bat launcher
Set-Content -Path C:\wp-cli\wp.bat -Value '@ECHO OFF`nphp "C:\wp-cli\wp-cli.phar" %*'
# Add folder to PATH for current session
$env:PATH += ";C:\wp-cli"
# Persist PATH permanently (add it to PATH in Environment Variables)
[Environment]::SetEnvironmentVariable("PATH", $env:PATH, [EnvironmentVariableTarget]::User)
# Test installation
wp --info
On Windows 11, PowerShell is the default terminal (exit Command prompot).
Some WP-CLI scripts call sh internally, which PowerShell doesn’t provide, so even with wp.bat you get 'sh' n’est pas reconnu.
→ still has to use Unix-like shell
Some WP-CLI scripts call sh internally, which PowerShell doesn’t provide, so even with wp.bat you get 'sh' n’est pas reconnu.
→ still has to use Unix-like shell