Free tutorials & notes in Hindi & English · Clean code examples 🧰 Free PDF & Image Tools →
🟢 Foundation  ·  Lesson 02

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.

💡 XAMPP = Apache + MySQL + PHP in one installer, for local development.

Installing XAMPP

  1. Download XAMPP from the official Apache Friends website.
  2. Run the installer and accept the defaults (it installs to C:\xampp on Windows).
  3. 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.

⚠️ If Apache will not start, another app may be using port 80 — close it or change Apache's port to 8080.

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
PHP is working!

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 htdocs folder.
  • 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 htdocs folder.
  • 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?
PHP runs on a web server, not by double-clicking a file. XAMPP bundles everything you need — the Apache server, PHP itself, and the MySQL database — so you can run PHP pages on your own computer while learning.
Where do I put my PHP files in XAMPP?
Inside the 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?
You opened it directly (like double-clicking) instead of through the server. Always run PHP via http://localhost/... so Apache processes it and shows the result, not the raw code.
What is phpMyAdmin in XAMPP?
phpMyAdmin is a visual tool to manage MySQL databases in your browser. In XAMPP you open it at http://localhost/phpmyadmin to create databases and tables without typing SQL by hand.
Apache will not start in XAMPP — what do I do?
Usually another program (often Skype or IIS) is using port 80. Either close that program, or change Apache to a different port (like 8080) in the XAMPP config, then open the site at http://localhost:8080.
← Back to PHP Tutorial
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

💻 Live Code Editor

This page's programs are ready here — run them, edit them, and learn. No installation needed.
Powered by OneCompiler. The code loads into the editor automatically — press Run to see the output. If the editor does not open, open it in a new tab.
Next topicPHP Syntax and Echo Your progress: 2 / 50 (4%) · Lesson 3 / 50 Continue →

How was this lesson?

Your feedback helps us make the content better.

Write a review or suggestion (optional)

After approval, your name and city may appear publicly with your review. Please do not write your email or phone number.

▶ CodingEasily on YouTube

Learn with video lessons in easy Hindi

Featured video: RDBMS Part 3 – Class XI Commerce IT

▶ Subscribe – it’s free