XAMPP

Complete guide to installing and using Apache and MySQL with XAMPP

What is XAMPP?

XAMPP is a free software package that contains Apache, MySQL, PHP and Perl. It's an all-in-one solution for developing web applications locally.

Installing XAMPP

Step 1: Download XAMPP

Visit the official Apache Friends page and download the version compatible with your operating system.

Step 2: Run the installer

Run the downloaded file and follow the installation wizard. Make sure to install it in a path without spaces.

Step 3: Select components

During installation, select Apache and MySQL as the main components.

Step 4: Finish installation

Complete the installation and launch the XAMPP Control Panel.

Apache Configuration

Start Apache

  • Open the XAMPP Control Panel
  • Click "Start" next to Apache
  • The indicator should turn green
  • Verify by going to http://localhost in your browser

Basic configuration

Apache's main configuration file is located at:

xampp/apache/conf/httpd.conf

Important directories

  • Document Root: xampp/htdocs/ - This is where you place your PHP files
  • Logs: xampp/apache/logs/ - Log files

MySQL Configuration

Start MySQL

  • In the Control Panel, click "Start" next to MySQL
  • The indicator should turn green
  • Go to phpMyAdmin in http://localhost/phpmyadmin

Security configuration

  • The root user initially has no password
  • Recommended: Set a password from phpMyAdmin
  • You can change the configuration in xampp/mysql/bin/my.ini

Connecting from PHP

MySQLi connection example:

<?php
$servername = "localhost";
$username = "root";
$password = "";
$database = "mi_base_datos";

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

if ($conn->connect_error) {
    die("Conexión fallida: " . $conn->connect_error);
}
echo "Conectado exitosamente";
?>

Testing the installation

Create a test file

Create a file info.php in xampp/htdocs/ with the following content:

<?php
phpinfo();
?>

Go to http://localhost/info.php to view the PHP information.

Common troubleshooting

Port already in use

If Apache doesn't start, it may be because port 80 is already in use. Change the port in the Apache configuration.

Access denied

On Windows, run XAMPP as administrator to avoid permission issues.

MySQL won't start

Check that no other MySQL service is running. You can change the port in the configuration.

How to change the MySQL port in XAMPP

If MySQL won't start because port 3306 is in use, follow these steps:

Step 1: Locate the configuration file

Go to the XAMPP folder and open: xampp/mysql/bin/my.ini

Step 2: Find the port configuration

In the file, look for the line that says:

port = 3306
Step 3: Change the port

Change the port number to an available one, for example:

port = 3307

Common alternative ports: 3307, 3308, 3309

Step 4: Save and restart

Save the file and restart the MySQL service from the XAMPP Control Panel.

Check ports in use

To see which ports are in use on your system:

On Windows (CMD):
netstat -ano | findstr :3306
On Linux/Mac (Terminal):
sudo lsof -i :3306

Configure the app for the new port

If you change the port, remember to update your applications:

Example PHP connection with custom port:
<?php
$servername = "localhost";
$username = "root";
$password = "";
$database = "mi_base_datos";
$port = 3307;

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

if ($conn->connect_error) {
    die("Conexión fallida: " . $conn->connect_error);
}
echo "Connected successfully on port $port";
?>