How to Install PHP on Windows - Complete Step-by-Step Guide

Mahesh Mahesh Waghmare
7 min read

Installing PHP on Windows is essential for PHP development, whether you’re building web applications, working with WordPress, or learning server-side programming. This guide covers all installation methods, from manual setup to using development stacks like XAMPP and WAMP.

PHP Installation Methods

There are three main ways to install PHP on Windows:

  1. Manual Installation - Download and configure PHP yourself (most control)
  2. XAMPP - Complete development stack with PHP, Apache, MySQL (easiest)
  3. WAMP - Windows-optimized development stack (Windows-specific)

Choosing a Method:

  • Beginners: Use XAMPP or WAMP for simplicity
  • Advanced Users: Manual installation for full control
  • Learning: Manual installation to understand setup
  • Quick Setup: XAMPP or WAMP for immediate development

Manual PHP Installation

Step 1: Download PHP

  1. Visit windows.php.net/download
  2. Choose Thread Safe (TS) or Non-Thread Safe (NTS):
    • TS: Use with Apache web server
    • NTS: Use with IIS or Nginx with FastCGI
  3. Download the ZIP package (not the installer)
  4. Choose the latest stable version (PHP 8.x recommended)

Step 2: Extract PHP

  1. Create a folder: C:\php (or your preferred location)
  2. Extract the downloaded ZIP file to this folder
  3. You should see files like php.exe, php.ini, etc.

Step 3: Configure php.ini

  1. In the PHP folder, find php.ini-development or php.ini-production
  2. Copy it and rename to php.ini
  3. Open php.ini in a text editor
  4. Configure essential settings (see Configuration section below)

Step 4: Add PHP to PATH

Add PHP directory to Windows PATH environment variable:

  1. Press Windows + R, type sysdm.cpl, press Enter
  2. Click Advanced tab → Environment Variables
  3. Under System Variables, find Path, click Edit
  4. Click New, add: C:\php (or your PHP path)
  5. Click OK on all dialogs
  6. Restart Command Prompt

Step 5: Verify Installation

Open Command Prompt and test:

php -v

Should display PHP version information.

Advertisement

Installation via XAMPP

XAMPP is the easiest way to get PHP running on Windows with Apache and MySQL included.

Download and Install

  1. Visit apachefriends.org
  2. Download XAMPP for Windows
  3. Run the installer
  4. Choose installation directory (default: C:\xampp)
  5. Select components: Apache, MySQL, PHP, phpMyAdmin
  6. Complete installation

PHP Location

XAMPP installs PHP at: C:\xampp\php\

Start Services

  1. Open XAMPP Control Panel
  2. Start Apache (and MySQL if needed)
  3. PHP is now available

Access PHP

Via Command Line:

  • Add C:\xampp\php to PATH, or
  • Use full path: C:\xampp\php\php.exe -v

Via Web Server:

  • Web root: C:\xampp\htdocs\
  • Access: http://localhost/

Configure PHP in XAMPP

Edit: C:\xampp\php\php.ini

XAMPP comes with a pre-configured php.ini that’s ready to use.

Installation via WAMP

WAMP is a Windows-specific development stack optimized for Windows.

Download and Install

  1. Visit wampserver.com
  2. Download WAMP Server (64-bit recommended)
  3. Run installer
  4. Choose installation directory (default: C:\wamp64)
  5. Complete installation

PHP Location

WAMP installs PHP at: C:\wamp64\bin\php\phpX.X\ (version-specific folder)

Start Services

  1. Launch WAMP Server from Start Menu
  2. Wait for icon to turn green in system tray
  3. PHP is now available

Switch PHP Versions

WAMP allows multiple PHP versions:

  1. Right-click WAMP icon → PHPVersion
  2. Select desired PHP version
  3. WAMP restarts with new version

Access PHP

Via Command Line:

  • Add specific PHP version folder to PATH
  • Example: C:\wamp64\bin\php\php8.2.0

Via Web Server:

  • Web root: C:\wamp64\www\
  • Access: http://localhost/

Configure PHP

Essential php.ini Settings

Open php.ini and configure:

Enable Extensions (remove ; to uncomment):

extension=curl
extension=fileinfo
extension=gd
extension=mbstring
extension=mysqli
extension=openssl
extension=pdo_mysql
extension=zip

Set Timezone:

date.timezone = "America/New_York"

Find your timezone: php.net/manual/en/timezones.php

Memory Limit (for development):

memory_limit = 256M

Upload Settings:

upload_max_filesize = 64M
post_max_size = 64M

Error Display (development only):

display_errors = On
display_startup_errors = On
error_reporting = E_ALL

Production Settings (disable for production):

display_errors = Off
display_startup_errors = Off
log_errors = On
error_log = "C:\php\logs\php_errors.log"

Extension Directory

Ensure extension directory is correct:

extension_dir = "ext"

For full path:

extension_dir = "C:\php\ext"

Add PHP to PATH

Adding PHP to PATH allows you to use php command from anywhere.

Method 1: System Properties

  1. Press Windows + R, type sysdm.cpl
  2. AdvancedEnvironment Variables
  3. System VariablesPathEdit
  4. New → Add PHP directory (e.g., C:\php)
  5. OK on all dialogs
  6. Restart Command Prompt

Method 2: Command Line (PowerShell as Admin)

[Environment]::SetEnvironmentVariable(
    "Path",
    [Environment]::GetEnvironmentVariable("Path", "Machine") + ";C:\php",
    "Machine"
)

Verify PATH

echo %PATH%

Look for your PHP directory in the output.

Test PHP Installation

Command Line Tests

Check Version:

php -v

Check Configuration:

php --ini

Check Loaded Extensions:

php -m

Run PHP Code:

php -r "echo 'PHP is working!';"

Web Server Test

Create test.php in web root:

<?php
phpinfo();
?>

Access via browser:

  • XAMPP: http://localhost/test.php
  • WAMP: http://localhost/test.php
  • Manual: Configure web server and access accordingly

Security Note: Remove phpinfo() files from production!

Test Common Extensions

php -r "echo extension_loaded('curl') ? 'curl: OK' : 'curl: Missing';"
php -r "echo extension_loaded('mysqli') ? 'mysqli: OK' : 'mysqli: Missing';"
php -r "echo extension_loaded('mbstring') ? 'mbstring: OK' : 'mbstring: Missing';"

Troubleshooting

PHP Not Recognized

Issue: php command not found

Solutions:

  1. Verify PHP is in PATH: echo %PATH%
  2. Restart Command Prompt completely
  3. Check installation directory exists
  4. Re-add to PATH if needed
  5. Restart computer if changes don’t take effect

Extensions Not Loading

Issue: Extensions not working

Solutions:

  1. Check extension_dir in php.ini
  2. Verify extension DLL files exist in ext\ folder
  3. Ensure extensions are uncommented in php.ini
  4. Check for Visual C++ Redistributable (required for some extensions)
  5. Verify PHP and extensions are same architecture (x86/x64)

Apache/PHP Integration Issues

Issue: PHP not working with Apache

Solutions:

  1. XAMPP/WAMP: Use their control panels to manage services
  2. Manual Apache: Configure httpd.conf to load PHP module
  3. Check Apache error logs
  4. Verify PHP module is loaded in Apache

Port Conflicts

Issue: Port 80 or 443 already in use

Solutions:

  1. Check what’s using the port: netstat -ano | findstr :80
  2. Stop conflicting service
  3. Change Apache port in configuration
  4. Use XAMPP/WAMP port management

Permission Errors

Issue: Cannot write files or access directories

Solutions:

  1. Run as Administrator if needed
  2. Check folder permissions
  3. Ensure web server has write access
  4. Check open_basedir restrictions in php.ini
Advertisement

Best Practices

Installation Location

  • Manual: Use C:\php for easy access
  • XAMPP: Default C:\xampp is fine
  • WAMP: Default C:\wamp64 is fine
  • Avoid spaces in paths if possible

Version Selection

  • LTS Versions: More stable, longer support
  • Latest Stable: New features, may have issues
  • Match Production: Use same version as production server

Security

  1. Development: Enable error display for debugging
  2. Production: Disable error display, enable logging
  3. Remove phpinfo(): Never expose in production
  4. Update Regularly: Keep PHP updated for security

Configuration Management

  1. Backup php.ini: Before making changes
  2. Document Changes: Keep notes of customizations
  3. Version Control: Track php.ini changes
  4. Test After Changes: Verify everything still works

Development Workflow

  1. Use Development Stack: XAMPP/WAMP for quick setup
  2. Local Testing: Test locally before deploying
  3. Match Environments: Keep dev/prod similar
  4. Use Version Control: Track code changes

Conclusion

Installing PHP on Windows is straightforward with the right method:

  • Quick Setup: Use XAMPP or WAMP
  • Full Control: Manual installation
  • Learning: Manual installation to understand setup

Key steps:

  1. Choose installation method
  2. Download and install PHP
  3. Configure php.ini
  4. Add to PATH
  5. Test installation
  6. Configure web server (if needed)

After installation:

  • Verify with php -v
  • Test extensions
  • Configure for your needs
  • Keep updated for security

PHP on Windows is ready for development. Choose the method that fits your needs and start building!

Advertisement
Mahesh Waghmare

Written by Mahesh Waghmare

I bridge the gap between WordPress architecture and modern React frontends. Currently building tools for the AI era.

Follow on Twitter

Read Next