🌙
Happy Karwa Chauth! Wishing all couples a blessed Karwa Chauth. May your bond grow stronger every year. From Team Job...
💬 Share
Web Development Tutorials

XAMPP Localhost Setup: Run PHP and MySQL on Your Computer (Step by Step)

Test PHP websites on your own computer before uploading. Here's a step-by-step XAMPP localhost setup, including common errors and fixes.

In this article · 8 sections
  1. Install XAMPP
  2. Your first page
  3. phpMyAdmin
  4. Copy a live site to localhost
  5. Common problems
  6. Alternatives
  7. When you're ready
  8. FAQs
  9. Is XAMPP safe?
  10. Can I run WordPress on XAMPP?

Editing PHP files directly on a live server is risky: one mistake and customers see an error. XAMPP localhost lets you run Apache, PHP and MySQL on your own computer, so you can build and test safely, then upload when ready.

Install XAMPP

  1. Download XAMPP from the official Apache Friends website (choose a PHP 8.x version)
  2. Install to the default C:\xampp folder
  3. Open the XAMPP Control Panel
  4. Click Start next to Apache and MySQL; both should turn green

Your first page

  1. Create a folder: C:\xampp\htdocs\mysite
  2. Add index.php:
<?php echo "Hello from localhost! PHP " . PHP_VERSION; ?>
  1. Open http://localhost/mysite/ in your browser

phpMyAdmin

Open http://localhost/phpmyadmin to create databases, tables and run SQL. Default user is root with no password on a fresh install (fine for local use only). See MySQL basics.

Copy a live site to localhost

  1. Download the site files from hosting (File Manager zip or FTP)
  2. Export the database from hosting phpMyAdmin
  3. Put the files in htdocs/yoursite
  4. Create a local database and import the SQL file
  5. Update the database credentials in the config file (e.g. localhost, root, empty password)
  6. If the site uses absolute URLs or .htaccess rewrites, adjust the base URL; enable mod_rewrite (on by default in XAMPP)

Common problems

Problem Fix
Apache won't start: port 80 in use Close Skype/IIS/other servers, or change Apache's port to 8080 in httpd.conf and use localhost:8080
MySQL won't start: port 3306 in use Another MySQL is running; stop it or change the port
Blank white page Turn on errors: ini_set('display_errors', 1); error_reporting(E_ALL);. See debugging PHP errors
Import fails: file too large Increase upload_max_filesize and post_max_size in php.ini, then restart Apache
Special characters broken Use utf8mb4 for the database and connection

Alternatives

Laragon (fast, Windows), MAMP (Mac), Docker (advanced), or PHP's built-in server: php -S localhost:8000.

When you're ready

Upload to your hosting: see deploy a PHP website to Hostinger. Keep code in Git: see Git basics.

FAQs

Is XAMPP safe?

It's for local development. Don't expose it to the internet.

Can I run WordPress on XAMPP?

Yes. Create a database, put WordPress in htdocs, and run the installer.

Was this article helpful?

Your answer helps us improve our guides

Share this article

Joboo Web

Web design, SEO & digital marketing team · Ludhiana, Punjab

Joboo Web has helped Indian businesses grow online since 2019 — building fast websites and running SEO, Google Ads and social campaigns for clients in 80+ cities. About us →

Keep reading

💬