How to Connect ESP32 with XAMPP Server on Windows: an easy guide

If you’re working on IoT projects, the ESP32 with XAMPP server combination offers a powerful way to create your own local server environment for testing, logging, and interacting with devices. In this guide, you’ll learn how to connect your ESP32 board to a XAMPP server running on Windows and send sensor data via HTTP POST requests.


Why Use ESP32 with XAMPP Server

The ESP32 is a Wi-Fi-enabled microcontroller widely used in smart home, industrial, and automation projects. Pairing ESP32 with XAMPP server allows developers to store, display, and manage sensor data locally without relying on cloud services.

Using XAMPP, which includes Apache, MySQL, and PHP, you can:

  • Create custom dashboards
  • Log data into a MySQL database
  • Use PHP to handle requests from ESP32
  • Visualize real-time sensor data locally

This setup is ideal for students, hobbyists, or professionals wanting full control over their data.


What You’ll Need

  • A Windows PC with XAMPP installed
  • ESP32 development board
  • Arduino IDE (with ESP32 board installed)
  • Basic knowledge of PHP
  • Wi-Fi connection

Step 1: Set Up the XAMPP Server

If you haven’t already, install and configure XAMPP:

  1. Download XAMPP from Apache Friends.
  2. Install it in C:\xampp.
  3. Open the XAMPP Control Panel and start Apache and MySQL.

Start apache server and mysql database

Create a Test PHP Script

  1. Go to C:\xampp\htdocs
  2. Create a file named esp_data.php with this code:

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $temperature = $_GET['temperature'];
    $humidity = $_GET['humidity'];

    $file = fopen("data.txt", "a");
    fwrite($file, "Temp: $temperature, Humidity: $humidity\n");
    fclose($file);

    echo "Data received successfully";
} else {
    echo "Invalid request";
}
?>

Save it as:

Save php file as esp_data

  1. Open a browser and test the script:
    Visit http://localhost/esp_data.php
    If it says “Invalid request,” it’s working (since it only accepts POST).

Checking if request is get or post

Step 2: Connect ESP32 with XAMPP Server

Arduino IDE Setup

  1. Open Arduino IDE
  2. Install the ESP32 board if you haven’t already

Sample Code for ESP32

Here’s how to send data from ESP32 to XAMPP using POST:

//ESP32 with xampp
#include <WiFi.h>
#include <HTTPClient.h>

const char* ssid = "Your_SSID";
const char* password = "Your_PASSWORD";

void setup() {
  Serial.begin(9600);
  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi...");
  }

  Serial.println("Connected to WiFi");
}

void loop() {
  if (WiFi.status() == WL_CONNECTED) {
    HTTPClient http;

   
    //http.addHeader("Content-Type", "application/x-www-form-urlencoded");

    int temperature = 25; // Replace with sensor value
    int humidity = 60;    // Replace with sensor value

    String postData = "temperature=" + String(temperature) + "&humidity=" + String(humidity);
 http.begin("http://192.168.100.15/esp_data.php?"+postData ); // Replace with your PC's IP
    int httpResponseCode = http.POST("");
Serial.println("http://192.168.1.100/esp_data.php?"+postData);
    if (httpResponseCode > 0) {
      String response = http.getString();
      Serial.println("Server response: " + response);
    } else {
      Serial.println("Error sending POST");
    }

    http.end();
  }

  delay(10000); // Send every 10 seconds
}

Replace 192.168.1.100 with the actual IP address of the PC running XAMPP (you can find it using ipconfig in CMD).

Also add your SSID and Password in code.

Getting PC IP from cmd

In my case this line will be updated http.begin(“http://192.168.1.100/esp_data.php”); to http.begin(“http://192.168.100.15/esp_data.php”);

Make sure ESP32 and PC are connected to same network


Step 3: View the Data

Go to C:\xampp\htdocs\data.txt to see the data saved by the ESP32. Each time the ESP32 sends a POST request, temperature and humidity values are logged to the file.

ESP32 with xampp text file output

Serial Monitor output should be like this:

Serial Monitor output

You can later enhance this setup by saving the data to a MySQL database instead of a .txt file.


Common Issues and Fixes

  • ESP32 not connecting to Wi-Fi: Check SSID and password
  • Connection refused: Ensure Apache is running in XAMPP
  • PHP file not responding: Use the correct local IP and path
  • Firewall blocking requests: Allow Apache through Windows Firewall

Conclusion

Using ESP32 with XAMPP server is an effective way to prototype and test IoT projects without needing internet access or third-party services. Whether you’re logging temperature, controlling devices, or building a dashboard, this setup gives you flexibility and control.

Start simple, then explore more advanced features like MySQL integration, data visualization, and real-time updates. If you’re serious about local IoT development, learning to use ESP32 with XAMPP server is a must.


IF YOU WANT to install XAMPP Server in windows:

How To Install XAMPP Server On Windows: A Step-by-Step Guide – ArduinoYard

Leave a Comment