Install PHP on Windows

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

  1. Visit the Apache Friends website
  2. Click the “Download” button
  3. Select the Windows version (XAMPP for Windows)
  4. Choose the version with PHP 8.x (latest stable version)

Step 2: Install XAMPP

  1. Run the downloaded installer

  2. Choose your installation directory (default: C:\xampp)

  3. 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
  4. Click “Next” and complete the installation

Step 3: Start Apache Server

  1. Open XAMPP Control Panel from your desktop or Start Menu
  2. Click “Start” next to Apache
  3. The Apache indicator should turn green
  4. Optionally start MySQL if you need a database

Step 4: Test Your PHP Installation

  1. Navigate to C:\xampp\htdocs (this is your web root)
  2. Create a new file called test.php
  3. Add this code to the file:
<?php
phpinfo();
?>
  1. Open your web browser and go to http://localhost/test.php
  2. 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

  1. Visit the PHP for Windows download page
  2. Download the latest “VS16 x64 Non Thread Safe” zip file
  3. Extract the zip to C:\php

Step 2: Configure PHP

  1. Navigate to C:\php
  2. Rename php.ini-development to php.ini
  3. Open php.ini in a text editor
  4. 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_ALL

Step 3: Add PHP to PATH

  1. Press Windows key and search “Environment Variables”
  2. Click “Edit the system environment variables”
  3. Click “Environment Variables…”
  4. Under “System variables”, find “Path” and click “Edit”
  5. Click “New” and add C:\php
  6. Click OK on all windows
  7. Restart Command Prompt or PowerShell

Step 4: Test Installation

Open Command Prompt and run:

php --version

You should see PHP version information.

Method 3: Using Docker

For modern development workflows, Docker provides isolated PHP environments.

Step 1: Install Docker Desktop

  1. Download Docker Desktop for Windows
  2. Install and start Docker Desktop

Step 2: Create PHP Container

  1. Create a folder for your project
  2. Create a docker-compose.yml file:
version: '3.8'
services:
  php:
    image: php:8.2-apache
    ports:
      - "8080:80"
    volumes:
      - .:/var/www/html
  1. In the same folder, create index.php:
<?php
echo "Hello from Docker PHP!";
?>
  1. Open Command Prompt in this folder and run:
docker-compose up -d
  1. Open http://localhost:8080 in your browser

Installing Composer (PHP Package Manager)

Composer is essential for modern PHP development.

Method 1: Installer

  1. Download Composer-Setup.exe
  2. Run the installer
  3. 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.exe

Popular IDEs and Editors for PHP on Windows

Visual Studio Code (Recommended)

  1. Download Visual Studio Code
  2. Install these extensions:
    • PHP Intelephense (code intelligence)
    • PHP Debug (debugging support)
    • Prettier (code formatting)

PhpStorm

  1. Download PhpStorm
  2. Professional PHP IDE with advanced features
  3. 30-day free trial, then paid license

Sublime Text

  1. Download Sublime Text
  2. 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_dir path in php.ini
  • Ensure DLL files exist in the ext folder
  • Restart Apache/XAMPP after changing configuration

4. Port 80 Already in Use

Solution:

  1. Open Command Prompt as Administrator
  2. Run: netstat -ano | findstr :80
  3. Find the process using port 80
  4. Stop that service or change Apache port in XAMPP config

Testing Different PHP Versions

Using Multiple PHP Versions with XAMPP

  1. Download different PHP versions from windows.php.net
  2. Extract to separate folders (e.g., C:\php7.4, C:\php8.0)
  3. 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:

  1. Learn Basic PHP Syntax: Variables, loops, functions
  2. Set Up a Development Environment: Choose an IDE and configure it
  3. Install Composer: Manage dependencies and packages
  4. Create Your First Project: A simple contact form or blog
  5. 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:

Last updated on