Install PHP on Windows
Installing PHP on Windows is straightforward using XAMPP, which provides a complete web development environment including Apache, MySQL, and PHP. This guide will walk you through the installation process step by step.
Method 1: XAMPP (Recommended for Beginners)
XAMPP is the most popular way to run PHP on Windows because it includes everything you need to start developing web applications immediately.
Step 1: Download XAMPP
- Visit the Apache Friends website
- Click the “Download” button
- Select the Windows version (XAMPP for Windows)
- Choose the version with PHP 8.x (latest stable version)
Step 2: Install XAMPP
Run the downloaded installer
Choose your installation directory (default:
C:\xampp)Select which components to install:
- Apache: Required (web server)
- MySQL: Recommended (database)
- PHP: Required (programming language)
- phpMyAdmin: Recommended (database management)
- Others: Optional based on your needs
Click “Next” and complete the installation
Step 3: Start Apache Server
- Open XAMPP Control Panel from your desktop or Start Menu
- Click “Start” next to Apache
- The Apache indicator should turn green
- Optionally start MySQL if you need a database
Step 4: Test Your PHP Installation
- Navigate to
C:\xampp\htdocs(this is your web root) - Create a new file called
test.php - Add this code to the file:
<?php
phpinfo();
?>
- Open your web browser and go to
http://localhost/test.php - You should see the PHP information page
Method 2: Manual Installation
If you prefer more control or need specific PHP configurations, you can install PHP manually.
Step 1: Download PHP Binaries
- Visit the PHP for Windows download page
- Download the latest “VS16 x64 Non Thread Safe” zip file
- Extract the zip to
C:\php
Step 2: Configure PHP
- Navigate to
C:\php - Rename
php.ini-developmenttophp.ini - Open
php.iniin a text editor - Make these important changes:
; Enable extensions (uncomment by removing ;)
extension_dir = "ext"
extension=curl
extension=gd
extension=mbstring
extension=mysqli
extension=openssl
extension=pdo_mysql
; Set timezone
date.timezone = "America/New_York"
; Error reporting for development
display_errors = On
error_reporting = E_ALLStep 3: Add PHP to PATH
- Press Windows key and search “Environment Variables”
- Click “Edit the system environment variables”
- Click “Environment Variables…”
- Under “System variables”, find “Path” and click “Edit”
- Click “New” and add
C:\php - Click OK on all windows
- Restart Command Prompt or PowerShell
Step 4: Test Installation
Open Command Prompt and run:
php --versionYou should see PHP version information.
Method 3: Using Docker
For modern development workflows, Docker provides isolated PHP environments.
Step 1: Install Docker Desktop
- Download Docker Desktop for Windows
- Install and start Docker Desktop
Step 2: Create PHP Container
- Create a folder for your project
- Create a
docker-compose.ymlfile:
version: '3.8'
services:
php:
image: php:8.2-apache
ports:
- "8080:80"
volumes:
- .:/var/www/html- In the same folder, create
index.php:
<?php
echo "Hello from Docker PHP!";
?>
- Open Command Prompt in this folder and run:
docker-compose up -d- Open
http://localhost:8080in your browser
Installing Composer (PHP Package Manager)
Composer is essential for modern PHP development.
Method 1: Installer
- Download Composer-Setup.exe
- Run the installer
- Follow the prompts (it will detect your PHP installation)
Method 2: Command Line
Open Command Prompt and run:
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php
php -r "unlink('composer-setup.php');"Move composer to a location in your PATH:
move composer.phar C:\php\composer.exePopular IDEs and Editors for PHP on Windows
Visual Studio Code (Recommended)
- Download Visual Studio Code
- Install these extensions:
- PHP Intelephense (code intelligence)
- PHP Debug (debugging support)
- Prettier (code formatting)
PhpStorm
- Download PhpStorm
- Professional PHP IDE with advanced features
- 30-day free trial, then paid license
Sublime Text
- Download Sublime Text
- Install PHP packages through Package Control
Common Windows-Specific Issues
1. “php is not recognized” Error
Solution: Ensure PHP is added to your Windows PATH environment variable and restart your terminal.
2. Permission Issues with XAMPP
Solution: Run XAMPP Control Panel as Administrator.
3. Extensions Not Loading
Solution:
- Check
extension_dirpath inphp.ini - Ensure DLL files exist in the
extfolder - Restart Apache/XAMPP after changing configuration
4. Port 80 Already in Use
Solution:
- Open Command Prompt as Administrator
- Run:
netstat -ano | findstr :80 - Find the process using port 80
- Stop that service or change Apache port in XAMPP config
Testing Different PHP Versions
Using Multiple PHP Versions with XAMPP
- Download different PHP versions from windows.php.net
- Extract to separate folders (e.g.,
C:\php7.4,C:\php8.0) - Switch versions by updating Apache configuration:
# in httpd-xampp.conf
LoadModule php_module "C:/php8.0/php8apache2_4.dll"
PHPIniDir "C:/php8.0"Next Steps
After installing PHP, you should:
- Learn Basic PHP Syntax: Variables, loops, functions
- Set Up a Development Environment: Choose an IDE and configure it
- Install Composer: Manage dependencies and packages
- Create Your First Project: A simple contact form or blog
- Learn a Framework: Laravel or Symfony for larger projects
Common Development Tools
Database Management
- phpMyAdmin: Included with XAMPP, web-based database admin
- HeidiSQL: Free SQL client for Windows
- DBeaver: Universal database tool
Version Control
- Git: Essential for version control
- GitHub Desktop: GUI for Git operations
- SourceTree: Another Git GUI option
Local Development
- Laragon: Lightweight alternative to XAMPP
- WampServer: Another Windows AMP stack
- Docker: For containerized development
External Resources
Related Tutorials: