How to Install and Use XAMPP for Local PHP Development (2025 Guide)
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.
2. How to Install XAMPP on Your Computer
Installing XAMPP is simple. Here’s how you can set up your local development server:
- Visit the official XAMPP website.
- Download the latest version for your operating system.
- Run the installer and select components like Apache, MySQL, PHP, and phpMyAdmin.
- Once installed, launch the XAMPP Control Panel.
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
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:
- Go to
http://localhost/phpmyadminin your browser. - Click on “New” in the sidebar.
- Enter a name like
my_databaseand 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!";
?>
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.
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.