PHP Setup with XAMPP (Step by Step)
In this lesson: Download XAMPP, start Apache & MySQL, save files in htdocs and run your first PHP page on localhost — easy Hindi & English steps.
Why you need a local server
PHP does not run by double-clicking a file — it needs a web server to process it. XAMPP is a free package that installs everything at once: the Apache web server, PHP, and the MySQL database. With it, you can build and test PHP sites right on your own computer.
Installing XAMPP
- Download XAMPP from the official Apache Friends website.
- Run the installer and accept the defaults (it installs to
C:\xamppon Windows). - Finish and launch the XAMPP Control Panel.
The Control Panel is the small window where you turn the server parts on and off.
Starting Apache and MySQL
In the XAMPP Control Panel, click Start next to Apache (the web server) and MySQL (the database). When both turn green, your local server is running.
The htdocs folder
Your PHP files must live in the htdocs folder inside XAMPP (for example C:\xampp\htdocs). Only files here are served by Apache. Make a folder for your project inside it, like htdocs/myapp.
Run your first file
Create htdocs/test.php with this code:
<?php
echo "PHP is working!";
?>
Then open your browser and go to:
http://localhost/test.php
If you see the message, your setup is complete. If you see the raw code instead, you opened the file directly — always use the http://localhost/ address.
Using phpMyAdmin
To manage databases visually, open:
http://localhost/phpmyadmin
Here you can create a database, add tables, and view data without typing SQL by hand. This is where you set up the database your PHP code will connect to.
Common mistakes
- Opening files by double-click. That shows code; always use
http://localhost/. - Files outside htdocs. Apache only serves files inside the
htdocsfolder. - Apache blocked on port 80. Close the conflicting app or switch to port 8080.
- Forgetting to start MySQL. Database code fails if MySQL is not running.
Summary
- PHP needs a web server; XAMPP bundles Apache, MySQL and PHP.
- Start Apache and MySQL from the XAMPP Control Panel.
- Put your PHP files inside the
htdocsfolder. - Open pages at
http://localhost/yourfile.php, not by double-click. - Manage databases at
http://localhost/phpmyadmin.
Next, learn the language basics in PHP syntax, or connect to a database with PHP MySQL connection.
Frequently Asked Questions
Why do I need XAMPP to run PHP?
Where do I put my PHP files in XAMPP?
htdocs folder in your XAMPP installation. Files placed there are served by Apache, so you open them in the browser at http://localhost/yourfile.php.Why does opening a .php file just show the code?
http://localhost/... so Apache processes it and shows the result, not the raw code.What is phpMyAdmin in XAMPP?
http://localhost/phpmyadmin to create databases and tables without typing SQL by hand.Apache will not start in XAMPP — what do I do?
http://localhost:8080.