How to Install PHP on Windows - Complete Step-by-Step Guide
Mahesh Waghmare 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:
- Manual Installation - Download and configure PHP yourself (most control)
- XAMPP - Complete development stack with PHP, Apache, MySQL (easiest)
- 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
- Visit windows.php.net/download
- Choose Thread Safe (TS) or Non-Thread Safe (NTS):
- TS: Use with Apache web server
- NTS: Use with IIS or Nginx with FastCGI
- Download the ZIP package (not the installer)
- Choose the latest stable version (PHP 8.x recommended)
Step 2: Extract PHP
- Create a folder:
C:\php(or your preferred location) - Extract the downloaded ZIP file to this folder
- You should see files like
php.exe,php.ini, etc.
Step 3: Configure php.ini
- In the PHP folder, find
php.ini-developmentorphp.ini-production - Copy it and rename to
php.ini - Open
php.iniin a text editor - Configure essential settings (see Configuration section below)
Step 4: Add PHP to PATH
Add PHP directory to Windows PATH environment variable:
- Press Windows + R, type
sysdm.cpl, press Enter - Click Advanced tab → Environment Variables
- Under System Variables, find Path, click Edit
- Click New, add:
C:\php(or your PHP path) - Click OK on all dialogs
- Restart Command Prompt
Step 5: Verify Installation
Open Command Prompt and test:
php -v
Should display PHP version information.
Installation via XAMPP
XAMPP is the easiest way to get PHP running on Windows with Apache and MySQL included.
Download and Install
- Visit apachefriends.org
- Download XAMPP for Windows
- Run the installer
- Choose installation directory (default:
C:\xampp) - Select components: Apache, MySQL, PHP, phpMyAdmin
- Complete installation
PHP Location
XAMPP installs PHP at: C:\xampp\php\
Start Services
- Open XAMPP Control Panel
- Start Apache (and MySQL if needed)
- PHP is now available
Access PHP
Via Command Line:
- Add
C:\xampp\phpto 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
- Visit wampserver.com
- Download WAMP Server (64-bit recommended)
- Run installer
- Choose installation directory (default:
C:\wamp64) - Complete installation
PHP Location
WAMP installs PHP at: C:\wamp64\bin\php\phpX.X\ (version-specific folder)
Start Services
- Launch WAMP Server from Start Menu
- Wait for icon to turn green in system tray
- PHP is now available
Switch PHP Versions
WAMP allows multiple PHP versions:
- Right-click WAMP icon → PHP → Version
- Select desired PHP version
- 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
- Press Windows + R, type
sysdm.cpl - Advanced → Environment Variables
- System Variables → Path → Edit
- New → Add PHP directory (e.g.,
C:\php) - OK on all dialogs
- 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:
- Verify PHP is in PATH:
echo %PATH% - Restart Command Prompt completely
- Check installation directory exists
- Re-add to PATH if needed
- Restart computer if changes don’t take effect
Extensions Not Loading
Issue: Extensions not working
Solutions:
- Check
extension_dirin php.ini - Verify extension DLL files exist in
ext\folder - Ensure extensions are uncommented in php.ini
- Check for Visual C++ Redistributable (required for some extensions)
- Verify PHP and extensions are same architecture (x86/x64)
Apache/PHP Integration Issues
Issue: PHP not working with Apache
Solutions:
- XAMPP/WAMP: Use their control panels to manage services
- Manual Apache: Configure
httpd.confto load PHP module - Check Apache error logs
- Verify PHP module is loaded in Apache
Port Conflicts
Issue: Port 80 or 443 already in use
Solutions:
- Check what’s using the port:
netstat -ano | findstr :80 - Stop conflicting service
- Change Apache port in configuration
- Use XAMPP/WAMP port management
Permission Errors
Issue: Cannot write files or access directories
Solutions:
- Run as Administrator if needed
- Check folder permissions
- Ensure web server has write access
- Check
open_basedirrestrictions in php.ini
Best Practices
Installation Location
- Manual: Use
C:\phpfor easy access - XAMPP: Default
C:\xamppis fine - WAMP: Default
C:\wamp64is 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
- Development: Enable error display for debugging
- Production: Disable error display, enable logging
- Remove phpinfo(): Never expose in production
- Update Regularly: Keep PHP updated for security
Configuration Management
- Backup php.ini: Before making changes
- Document Changes: Keep notes of customizations
- Version Control: Track php.ini changes
- Test After Changes: Verify everything still works
Development Workflow
- Use Development Stack: XAMPP/WAMP for quick setup
- Local Testing: Test locally before deploying
- Match Environments: Keep dev/prod similar
- 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:
- Choose installation method
- Download and install PHP
- Configure php.ini
- Add to PATH
- Test installation
- 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!
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 →