Setting up a local server with XAMPP is one of the first steps every web developer should master. Whether you’re building a PHP project, testing a WordPress site, or learning database management, XAMPP lets you run a complete web environment directly on your computer. In this guide, you’ll learn how to install XAMPP, configure Apache and MySQL, and connect a PHP application to a database — all locally and step by step.

1. What is XAMPP and Why You Should Use It

XAMPP is a free, open-source development environment that combines essential web tools: Apache (web server), MySQL (database server), PHP (backend language), and phpMyAdmin (database management interface). It allows developers to create and test websites offline, which is perfect for learning, prototyping, and debugging.

  • Apache: Handles HTTP requests and runs your PHP scripts.
  • MySQL: Stores and manages all your application data.
  • PHP: The main programming language for dynamic websites and CMSs like WordPress or Joomla.
  • phpMyAdmin: Provides an easy web interface to manage your databases visually.
💡 Developer Tip: XAMPP is cross-platform and works on Windows, macOS, and Linux. It’s ideal for both beginners and professionals working with PHP and MySQL locally.

2. How to Install XAMPP on Your Computer

Installing XAMPP is simple. Here’s how you can set up your local development server:

  1. Visit the official XAMPP website.
  2. Download the latest version for your operating system.
  3. Run the installer and select components like Apache, MySQL, PHP, and phpMyAdmin.
  4. Once installed, launch the XAMPP Control Panel.
⚙️ Pro Tip: Make sure both Apache and MySQL show a green “Running” status in the control panel. This means your local server is active and ready to use!

3. Creating Your First Local Website

Once XAMPP is installed, place your web files inside the htdocs folder, located in your XAMPP directory. For example:

C:\xampp\htdocs

Create a new project folder called my_website and inside it, add an index.php file with the following code:

<?php
echo "Hello, world! Your local server is running!";
?>

Now, open your browser and go to:

http://localhost/my_website
🚀 Quick Test: If you see the “Hello, world!” message, congratulations — your local server setup is working perfectly!

4. How to Create and Connect a MySQL Database in XAMPP

With XAMPP, you can manage databases directly through phpMyAdmin. To create a new database:

  1. Go to http://localhost/phpmyadmin in your browser.
  2. Click on “New” in the sidebar.
  3. Enter a name like my_database and click “Create”.

Then, connect your PHP file to this database using the following code:

<?php
$servername = "localhost";
$username = "root";
$password = ""; // default password is empty
$dbname = "my_database";

$conn = new mysqli($servername, $username, $password, $dbname);

if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}
echo "Database connected successfully!";
?>
🧠 Tip: Always ensure MySQL is running before executing database-related PHP code. Otherwise, you’ll get connection errors.

5. Testing Your PHP and MySQL Connection

Save the above script as connect.php inside your project folder and open:

http://localhost/my_website/connect.php

If you see the message “Database connected successfully!”, your local PHP project is now fully connected to MySQL using XAMPP.

6. Troubleshooting Common XAMPP Problems

  • Apache not starting: Another app (like Skype or IIS) may be using port 80. Change Apache’s port to 8080 under Settings → Config → Service and Port Settings.
  • MySQL won’t run: Check logs for port conflicts or restart the module from the Control Panel.
  • Access denied: Verify the username and database name in your PHP connection file.
Advanced Tip: Use tools like HeidiSQL or MySQL Workbench for advanced database management and visualization.

7. Final Thoughts

Setting up a local server with XAMPP is a must-have skill for any developer. It allows you to test, debug, and optimize your PHP and MySQL projects without needing a live server. Whether you’re building a simple login system, a CRUD app, or a full WordPress theme, XAMPP gives you a safe, fast, and flexible development environment.

🚀 Next Step: Visit our blog for in-depth tutorials on creating login systems, PHP CRUD applications, and full-stack projects using XAMPP and MySQL.