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
Web Server
Programming Language
Database
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.
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:
You can keep this location unless you have a specific reason to change it.
Open XAMPP Control Panel
After installation, open the XAMPP Control Panel.
You will see services such as:
Click Start next to Apache and MySQL.
MySQL — Running
Test Apache
Open your web browser and visit:
You should see the XAMPP welcome or dashboard page. This confirms that Apache is working.
Create Your First PHP Page
XAMPP stores website files inside:
Create a folder named:
Inside the folder, create:
index.php
Add PHP Code
<?php
echo "Hello, PHP!";
?>
Open the Page
Hello, PHP!
Check Your PHP Version
You can check whether PHP is working
correctly using the phpinfo()
function.
<?php
phpinfo();
?>
Do not leave a public
phpinfo()
page accessible on a production server.
Open phpMyAdmin
phpMyAdmin provides a graphical interface for managing MySQL/MariaDB databases.
You can use phpMyAdmin to:
- Create databases
- Create tables
- Insert records
- Edit records
- Delete records
- Run SQL queries
Create Your First Database
Open phpMyAdmin and select New.
Create a database named:
Then create a table called:
Example Table
| Column | Type | Purpose |
|---|---|---|
| id | INT | User ID |
| name | VARCHAR (100) | User name |
| VARCHAR (150) | Email address |
Set id as the primary key
and enable auto-increment.
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:
Database connected successfully.
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.
Your Project Location
\mywebsite
Website URL
/mywebsite/
Common XAMPP URLs
| Purpose | URL |
|---|---|
| XAMPP Dashboard | http:// |
| Your Website | http://localhost |
| phpMyAdmin | http://localhost |
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
.phpextension. - The PHP file is inside
C:\xampp\htdocs. - You are opening the page through
http://localhost.
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