Created
September 2, 2024 03:10
-
-
Save devkabir/6ad0003e01a01ed83e3529362751555e to your computer and use it in GitHub Desktop.
Install WP Cli on windows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # PowerShell Script to Install WP-CLI on Windows | |
| # Step 1: Download WP-CLI Phar file | |
| $wpcli_url = "https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar" | |
| $destination = "C:\wp-cli\wp-cli.phar" | |
| # Create directory if it doesn't exist | |
| if (!(Test-Path "C:\wp-cli")) { | |
| New-Item -ItemType Directory -Path "C:\wp-cli" | |
| } | |
| Write-Host "Downloading WP-CLI..." | |
| Invoke-WebRequest -Uri $wpcli_url -OutFile $destination | |
| # Step 2: Make the file executable | |
| Write-Host "Making the file executable..." | |
| Set-ItemProperty -Path $destination -Name IsReadOnly -Value $false | |
| Set-ExecutionPolicy RemoteSigned -Scope CurrentUser | |
| # Step 3: Create a batch file to easily run WP-CLI commands | |
| $batchFileContent = '@echo off | |
| php "C:\wp-cli\wp-cli.phar" %*' | |
| $batchFilePath = "C:\wp-cli\wp.bat" | |
| Set-Content -Path $batchFilePath -Value $batchFileContent | |
| # Step 4: Add WP-CLI to system PATH | |
| $envPath = [System.Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::Machine) | |
| if ($envPath -notlike "*C:\wp-cli*") { | |
| Write-Host "Adding C:\wp-cli to system PATH..." | |
| [System.Environment]::SetEnvironmentVariable("Path", "$envPath;C:\wp-cli", [System.EnvironmentVariableTarget]::Machine) | |
| } | |
| Write-Host "WP-CLI installation completed successfully. Open a new command prompt and type 'wp' to use WP-CLI." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment