Skip to content
💻 🧠 Code 1001 > 🛠️ DevOps > 🚀 Complete Guide: How to Run Apache in XAMPP on Windows (with All Common Pitfalls)

🚀 Complete Guide: How to Run Apache in XAMPP on Windows (with All Common Pitfalls)

🧭 Introduction

XAMPP is a local web server package that includes Apache, MySQL (MariaDB), PHP, and Perl.
The Apache service is the core of it — it serves your website when you open http://localhost.

However, many developers encounter issues when trying to start Apache:

  • ❌ “Failed to start Apache2.4 service. Error code 1”
  • ⚠️ “Port 80 in use”
  • 🔒 “Your connection is not private” or “NET::ERR_CERT_COMMON_NAME_INVALID”

This guide walks you through every step — from installation to resolving all typical errors.


🧩 Installing XAMPP

  1. Download the latest version of XAMPP from the official site:
    👉 https://www.apachefriends.org/download.html
  2. Install XAMPP to a simple path (avoid spaces or Cyrillic characters), for example: E:\xampp
  3. After installation, run XAMPP Control Panel as Administrator.

🟢 Starting Apache for the First Time

  1. In the XAMPP Control Panel, click Start next to Apache.
  2. If it works, you’ll see: Apache ... running
  3. Open in your browser: http://localhost/ You should see the XAMPP welcome page.

If Apache doesn’t start — read on.


❗ Common Problems and Solutions


⚙️ 1. “Apache2.4 service failed to start. Error code 1”

Cause: The configuration file is broken, or the SSL key file is missing.

Check:

Open PowerShell or CMD as Administrator:

cd E:\xampp\apache\bin
.\httpd.exe -t

If you see:

AH00526: Syntax error on line 158 of E:/xampp/apache/conf/extra/httpd-ssl.conf:
SSLCertificateKeyFile: file 'E:/xampp/apache/conf/ssl/server.key' does not exist or is empty

then the SSL certificate is missing.

Fix:

Generate a new self-signed certificate:

cd E:\xampp\apache\bin
.\openssl.exe req -x509 -nodes -days 1095 -newkey rsa:2048 `
 -keyout "../conf/ssl/server.key" `
 -out "../conf/ssl/server.crt"

You can simply press Enter through the prompts or enter details:

Country Name: IL
State: Israel
Locality: Jerusalem
Organization: hypo69
Common Name: localhost

🔒 2. “Your connection is not private” or NET::ERR_CERT_COMMON_NAME_INVALID

Cause: Modern browsers (Chrome, Edge, Firefox) no longer trust certificates that only specify CN=localhost.
They require the field subjectAltName (SAN).

Fix:

  1. Create a new file: E:\xampp\apache\conf\openssl-local.cnf
  2. Paste this configuration: [ req ] default_bits = 2048 prompt = no default_md = sha256 x509_extensions = v3_req distinguished_name = req_distinguished_name [ req_distinguished_name ] C = IL ST = Israel L = Jerusalem O = hypo69 OU = Dev CN = localhost [ v3_req ] subjectAltName = @alt_names [ alt_names ] DNS.1 = localhost IP.1 = 127.0.0.1
  3. Generate a new certificate: cd E:\xampp\apache\bin .\openssl.exe req -config "E:\xampp\apache\conf\openssl-local.cnf" ` -x509 -nodes -days 1095 -newkey rsa:2048 ` -keyout "../conf/ssl/server.key" ` -out "../conf/ssl/server.crt"
  4. Add it to Windows trusted store: Import-Certificate -FilePath "E:\xampp\apache\conf\ssl\server.crt" ` -CertStoreLocation Cert:\LocalMachine\Root (or manually: Install Certificate → Local Machine → Trusted Root Certification Authorities)
  5. Restart Apache: net stop apache2.4 net start apache2.4

✅ Now both https://localhost and https://127.0.0.1 should load securely.


🔌 3. “Port 80 or 443 already in use”

Check:

netstat -ano | findstr :80
netstat -ano | findstr :443

If occupied, find the process:

tasklist | findstr <PID>

Typical culprits:

  • Skype
  • IIS (World Wide Web Publishing Service)
  • VMware
  • Edge Update Service

Fix:

  1. Stop or disable the conflicting service.
  2. Or change Apache’s ports:

Edit E:\xampp\apache\conf\httpd.conf:

Listen 80

→ change to:

Listen 8080

Then in E:\xampp\apache\conf\extra\httpd-ssl.conf:

Listen 443

→ change to:

Listen 8443

Now open:

http://localhost:8080
https://localhost:8443

🔥 4. “Service Control Manager 7024: Incorrect function”

Cause: The Windows service entry for Apache is corrupted.

Fix:

Re-register Apache:

cd E:\xampp\apache\bin
httpd.exe -k uninstall
httpd.exe -k install

📄 5. Apache Error Logs

All logs are here:

E:\xampp\apache\logs\error.log

Read the last lines:

Get-Content E:\xampp\apache\logs\error.log -Tail 30

⚙️ Useful Diagnostic Commands

CommandDescription
httpd.exe -tValidate Apache configuration
httpd.exe -SShow virtual hosts
net start apache2.4Start Apache service
net stop apache2.4Stop Apache service
netstat -anoShow active ports
`tasklistfindstr PID`
certmgr.mscView installed certificates
services.mscManage Windows services

🌐 Setting Up Virtual Hosts (Custom Domains)

You can make your project billing-crm open at https://crm.local instead of localhost/billing-crm.

  1. Edit your hosts file: C:\Windows\System32\drivers\etc\hosts Add: 127.0.0.1 crm.local
  2. Edit: E:\xampp\apache\conf\extra\httpd-vhosts.conf Add: <VirtualHost *:443> ServerName crm.local DocumentRoot "E:/xampp/htdocs/billing-crm" SSLEngine on SSLCertificateFile "E:/xampp/apache/conf/ssl/server.crt" SSLCertificateKeyFile "E:/xampp/apache/conf/ssl/server.key" </VirtualHost>
  3. Test configuration: httpd.exe -t
  4. Restart Apache, then open: https://crm.local

🧠 Common Pitfalls and Tips

ProblemCauseFix
Apache won’t start at bootPort conflictStart XAMPP manually
“Connection not secure”Missing SANRecreate certificate with alt_names
HTTPS not respondingWrong port or missing keyCheck httpd-ssl.conf
Firefox still shows warningFirefox uses its own cert storeImport server.crt manually via settings
Empty index.phpBroken or missing projectRestore from Git or backup

🎯 Summary

StepPurposeCommand
Check configValidate Apache syntaxhttpd.exe -t
Generate SSLCreate localhost certificateopenssl req -config ...
Trust certAvoid HTTPS warningsImport-Certificate
Check portsEnsure 80/443 are freenetstat -ano
Start ApacheRun servicenet start apache2.4

📚 Conclusion

After following these steps:

  • Apache runs cleanly and starts without errors.
  • HTTPS works without browser warnings.
  • localhost, 127.0.0.1, and custom domains like crm.local are fully trusted.
  • You can develop and test web projects securely just like on a production server.

Leave a Reply

Your email address will not be published. Required fields are marked *