How to Install PHP Using PowerShell on Windows

How to Install PHP Using PowerShell on Windows

Published by Nuvora Editorial

5 min readUpdated Nov 27, 2026

Share
Nuvora VideoYouTube · Privacy-enhanced player

PHP is a popular server-side language used to build websites, APIs, and web applications. On Windows, you can install PHP quickly through PowerShell using Microsoft’s official installation script or the

winget

package manager. This guide walks you through the process step by step, from installing PHP to verifying that it works correctly.

Prerequisites

Before starting, make sure your Windows PC meets these basic requirements:

  • Windows 10 or Windows 11.
  • PowerShell installed; it is included by default on modern Windows.
  • An administrator PowerShell window for system-wide installation.
  • An internet connection to download PHP and its dependencies.

You can check your PowerShell version by opening PowerShell and running:

$PSVersionTable.PSVersion

If you plan to use PHP with Microsoft SQL Server later, you may also need the Microsoft ODBC Driver and Visual C++ Redistributable, which should match your PHP architecture (x64 or x86).

Install PHP With PowerShell

The simplest official method is to use the PHP download script directly in PowerShell. Open PowerShell as Administrator, then run:

powershell -c "& ([ScriptBlock]::Create((irm 'https://www.php.net/include/download-instructions/windows.ps1'))) -Version 8.3"

This command downloads and installs PHP 8.3 on Windows automatically. You can replace 8.3 with another supported PHP version if your project requires it.

After installation, close and reopen PowerShell so Windows refreshes the system PATH. Then test PHP with:

php --version

If PHP installed successfully, you should see output showing the PHP version, such as PHP 8.3.x.

Install PHP With Winget

Another easy method is to use Windows Package Manager (winget). Open PowerShell as Administrator and run:

winget install --exact --id PHP.PHP.8.5 --source winget --accept-package-agreements --accept-source-agreements

This command installs PHP 8.5 and accepts the required package agreements automatically. Microsoft documents this approach as a supported installation method for PHP on Windows.

After the installation finishes, refresh your PowerShell session:

$env:Path = [Environment]::GetEnvironmentVariable("Path", "Machine") + ";" +
[Environment]::GetEnvironmentVariable("Path", "User")

Then verify the installation:

php --version

If the command is not recognized, restart PowerShell or your computer, then try again.

Add PHP to PATH

PHP must be available in the Windows PATH so you can run php from any folder. Most modern installers add it automatically, but you can verify it manually.

Run this command to locate PHP:

Get-Command php

If PowerShell returns a path such as C:\Program Files\PHP\php.exe, PHP is already configured correctly. Microsoft recommends adding the PHP directory to PATH when installing PHP manually from a ZIP archive.

To add PHP manually using PowerShell, replace C:\php with your actual PHP folder:

$phpPath = "C:\php"
[Environment]::SetEnvironmentVariable(
  "Path",
  [Environment]::GetEnvironmentVariable("Path", "User") + ";" + $phpPath,
  "User"
)

Close and reopen PowerShell, then run:

php --version

Create a PHP Configuration File

PHP usually needs a php.ini configuration file for extensions and settings. Many PHP installations include a sample file named php.ini-development.

Run these commands to create it automatically:

$phpDirectory = Split-Path (Get-Command php.exe -ErrorAction Stop).Source
$phpIni = Join-Path $phpDirectory "php.ini"

if (-not (Test-Path $phpIni)) {
  Copy-Item (Join-Path $phpDirectory "php.ini-development") $phpIni
}

This script finds the PHP installation folder and copies php.ini-development to php.ini only if the configuration file does not already exist. Microsoft uses a similar approach in its PHP setup instructions.

To check which configuration file PHP is using, run:

php --ini

Enable Common PHP Extensions

Many web applications require extensions such as openssl and zip. You can enable them by editing php.ini.

First, open the file in Notepad:

notepad $phpIni

Find these lines and remove the semicolon (;) at the beginning:

;extension=openssl
;extension=zip

Change them to:

extension=openssl
extension=zip

Save the file and restart PowerShell. You can confirm loaded extensions with:

php -m

This command lists all active PHP modules and extensions.

Test PHP With a Script

Create a test file to make sure PHP can execute code. Run:

New-Item -ItemType Directory -Force C:\php-test | Out-Null
Set-Location C:\php-test
Set-Content -Path index.php -Value "<?php echo 'PHP is working on Windows!';"
php index.php

If everything is configured properly, PowerShell will display:

PHP is working on Windows!

You can also start PHP’s built-in development server:

php -S localhost:8000

Then open http://localhost:8000 in your browser. This is useful for testing local PHP projects before deploying them to a web server.

Common Problems and Fixes

Problem Likely cause Solution
php is not recognized PHP is not in PATH Add the PHP folder to PATH and restart PowerShell
PHP installs but does not run Missing Visual C++ Redistributable Install the redistributable matching your PHP architecture
Extensions do not load php.ini is missing or extensions are commented out Create php.ini and enable required extensions
Wrong PHP version runs Another PHP installation exists in PATH Check Get-Command php and adjust the PATH order
Permission error PowerShell was not opened as Administrator Reopen PowerShell using Run as administrator

Final Thoughts

Installing PHP on Windows with PowerShell is fast, repeatable, and ideal for developers who prefer command-line tools. The official PHP PowerShell installer is the most straightforward option, while winget is a great alternative if you already use Windows Package Manager. Once PHP is installed, verify it with php --version, configure php.ini, and test a simple script to ensure your development environment is ready.

For AdSense-friendly publishing, keep the article original, helpful, and focused on solving a clear technical problem. Avoid copying documentation word-for-word, add your own explanations and screenshots where possible, and use headings, code blocks, and a logical structure to improve readability.

About this publication

Nuvora Editorial

Publication byline for Nuvora, an independently operated digital publication. This profile identifies articles published under the Nuvora name; it is not a separate staff writer. Individual contributors should be credited by their real names when they write or report a story.

Comments

Join the discussion. Sign in with GitHub to leave a comment.

Popular stories ranked by freshness, engagement, and reader interest

Explore articles

Selected for you

Recommendations

Explore all