Set Up PHP + MySQL Using XAMPP on Windows | Beginner Guide

Set Up PHP + MySQL Using XAMPP on Windows | Beginner Guide

9th August, 2026

Introduction

If you want to start developing PHP websites on your Windows computer, XAMPP is one of the easiest ways to create a local PHP and MySQL development environment.

With XAMPP, you can run PHP, Apache, and MySQL locally without needing a live web server.

What You Will Install

🌐 Apache

A web server that processes and serves your PHP pages.

🐘 PHP

A server-side programming language used to build dynamic websites.

🗄️ MySQL / MariaDB

A database server used to store application data.

🛠️ phpMyAdmin

A web-based interface for managing databases.

How the Environment Works

Your Windows Computer
XAMPP
Apache
Web Server
PHP
Programming Language
MySQL
Database
1

Download XAMPP

Download XAMPP for Windows from the official Apache Friends website.

After downloading it, you should have an installer similar to:

xampp-windows-x64-....exe

Run the installer to begin the setup.

2

Install XAMPP

During installation, keep the default components selected.

Apache : Web server
PHP: Runs PHP applications
MySQL / MariaDB: Database server
phpMyAdmin: Database management

The default installation directory is usually:

C:\xampp

You can keep this location unless you have a specific reason to change it.

3

Open XAMPP Control Panel

After installation, open the XAMPP Control Panel.

You will see services such as:

🌐 Apache
🗄️ MySQL

Click Start next to Apache and MySQL.

Apache — Running
MySQL — Running
4

Test Apache

Open your web browser and visit:

http://localhost/

You should see the XAMPP welcome or dashboard page. This confirms that Apache is working.

5

Create Your First PHP Page

XAMPP stores website files inside:

C:\xampp\htdocs

Create a folder named:

C:\xampp\htdocs\mywebsite

Inside the folder, create:

index.php

Add PHP Code

<?php

echo "Hello, PHP!";

?>

Open the Page

http://localhost/mywebsite/
Expected Output:
Hello, PHP!
6

Check Your PHP Version

You can check whether PHP is working correctly using the phpinfo() function.

<?php
                                
                                phpinfo();
                                
                                ?>
http://localhost/mywebsite/
Security Note:
Do not leave a public phpinfo() page accessible on a production server.
7

Open phpMyAdmin

phpMyAdmin provides a graphical interface for managing MySQL/MariaDB databases.

http://localhost/phpmyadmin/

You can use phpMyAdmin to:

  • Create databases
  • Create tables
  • Insert records
  • Edit records
  • Delete records
  • Run SQL queries
8

Create Your First Database

Open phpMyAdmin and select New.

Create a database named:

mywebsite

Then create a table called:

users

Example Table

Column Type Purpose
id INT User ID
name VARCHAR (100) User name
email VARCHAR (150) Email address

Set id as the primary key and enable auto-increment.

9

Connect PHP to MySQL

Create a file named:

db.php

Add the following code:

<?php $host = "localhost"; $user = "root"; $password = ""; $database = "mywebsite"; $conn = new mysqli( $host, $user, $password, $database ); if ($conn->connect_error) { die("Database connection failed: " . $conn->connect_error); } echo "Database connected successfully."; ?>

Open:

http://localhost/
mywebsite/db.php
Expected Output:
Database connected successfully.
Important:
A default XAMPP installation may use the local root account without a password. For production applications, create a dedicated database user with a strong password.

Your Development Environment Is Ready

You now have a basic local PHP + MySQL development environment.

Windows PC
XAMPP
Apache + PHP
MySQL / MariaDB
phpMyAdmin

Your Project Location

C:\xampp\htdocs
\mywebsite

Website URL

http://localhost
/mywebsite/

Common XAMPP URLs

Purpose URL
XAMPP Dashboard http://
localhost/
Your Website http://localhost
/mywebsite/
phpMyAdmin http://localhost
/phpmyadmin/

Common XAMPP Problems

Apache Won't Start

Another application may already be using a port required by Apache.

Common causes include:

  • IIS
  • Another web server
  • Another Apache installation
  • Other applications using the same ports

MySQL Won't Start

Another MySQL or MariaDB service may already be running on your computer.

Check Windows Services and look for an existing MySQL or MariaDB service.

PHP Page Downloads Instead of Running

Check the following:

  • Apache is running.
  • The file has a .php extension.
  • The PHP file is inside C:\xampp\htdocs.
  • You are opening the page through http://localhost.
Incorrect:
file:///C:/xampp/htdocs/
mywebsite/index.php


Correct:
http://localhost/
mywebsite/index.php

Quick Setup Checklist

  • ✅ XAMPP installed
  • ✅ Apache running
  • ✅ MySQL/MariaDB running
  • ✅ localhost works
  • ✅ PHP page executes
  • ✅ phpMyAdmin opens
  • ✅ Database created
  • ✅ PHP connects to database

What to Learn Next

1. PHP Basics
Learn variables, conditions, loops and functions.
2. HTML + CSS
Learn how to create and style web pages.
3. PHP Forms
Learn how to process user input.
4. MySQL
Learn databases, tables and SQL queries.
5. PHP + MySQL CRUD
Build Create, Read, Update and Delete applications.
6. Sessions & Authentication
Learn login systems and user sessions.
7. CodeIgniter / Laravel
Move on to a PHP framework.
8. Build a Real Project
Apply everything you have learned in a complete web application.