127.0.0.1 — the loopback address. Every OS speaks it. Every developer uses it. But how do you actually add a localhost server on your machine? This is the full guide, for Windows, macOS, and Linux. No missing steps. No skipped details. Pick your OS, follow the block, and your machine will answer to localhost.

All software links are in the badges below each section. Everything is free unless noted. Everything works in 2026.

WINDOWS

Option 1 — XAMPP (easiest, recommended)

XAMPP is Apache + MariaDB + PHP + Perl in one installer. Free, open source, cross-platform.

  1. Go to the Apache Friends website and download XAMPP for Windows.
  2. Run the installer. Default path C:\xampp. Keep Apache, MySQL, PHP checked.
  3. Open XAMPP Control Panel from the Start Menu.
  4. Click Start next to Apache and MySQL.
  5. Open your browser and go to http://localhost. The XAMPP welcome page appears — you're done.

Your PHP files go in C:\xampp\htdocs\. Access them at http://localhost/yourfile.php.

Option 2 — WAMP Server

Windows-only alternative to XAMPP. Apache + MySQL + PHP. Slightly lighter, same idea.

  1. Download from WampServer.com.
  2. Install (needs Visual C++ Redistributable — the installer will tell you).
  3. Launch WampServer. Icon turns green when Apache and MySQL are running.
  4. Visit http://localhost. Files go in C:\wamp64\www\.

Option 3 — Laragon

Modern, fast, portable. Great for Laravel and WordPress. Free.

  1. Download from Laragon.org.
  2. Extract and run Laragon.exe. Click Start All.
  3. Visit http://localhost. Files go in C:\laragon\www\.

Option 4 — WSL2 + LAMP (closest to production Linux)

Best if you deploy to Linux servers. Runs a real Ubuntu/AlmaLinux inside Windows.

  1. Open PowerShell as Administrator and run the install command.
wsl --install --no-distribution
  1. Install Ubuntu or AlmaLinux from the Microsoft Store.
  2. Open the distro, create your user, then run the LAMP install block below (same as Linux).
  3. Visit http://localhost in your Windows browser — WSL2 forwards it automatically.
PORT 80 CONFLICT? Skype, IIS, or another web server may already use port 80. Apache won't start. Fix: close the conflicting app, or change Apache's port in httpd.conf to 8080 and visit http://localhost:8080.

MACOS

Option 1 — XAMPP (same as Windows)

  1. Download XAMPP for macOS from Apache Friends.
  2. Open the .dmg, drag XAMPP to Applications.
  3. Launch XAMPP, click Start next to Apache and MySQL.
  4. Visit http://localhost. Files go in /Applications/XAMPP/htdocs/.

Option 2 — MAMP (macOS classic)

Free version: Apache + MySQL + PHP. Pro version adds more. Default port is 8888, not 80.

  1. Download from MAMP.info.
  2. Open the .dmg, drag MAMP to Applications.
  3. Launch MAMP, click Start Servers.
  4. Browser opens http://localhost:8888 automatically. Files go in /Applications/MAMP/htdocs/.

Option 3 — Homebrew + PHP built-in server (lightest)

If you already use Homebrew, this is the fastest way to serve a single PHP file.

brew install php cd /path/to/your/project php -S localhost:8000

Visit http://localhost:8000. No Apache, no MySQL — just PHP. Perfect for quick tests.

Option 4 — Homebrew + Nginx + MySQL (manual LAMP)

brew install nginx brew install mysql brew install php brew services start nginx brew services start mysql brew services start php

Nginx default web root on Intel Mac: /usr/local/var/www. On Apple Silicon: /opt/homebrew/var/www.

APPLE SILICON NOTE: Homebrew installs to /opt/homebrew on M1/M2/M3/M4 Macs, not /usr/local. Adjust all paths accordingly.

LINUX (Ubuntu / Debian / AlmaLinux / Fedora)

Option 1 — apt LAMP (Ubuntu / Debian — cleanest)

The standard way. Apache + MySQL + PHP, all from the package manager.

sudo apt update && sudo apt upgrade -y sudo apt install -y apache2 sudo apt install -y mysql-server sudo mysql_secure_installation sudo apt install -y php libapache2-mod-php php-mysql php-mbstring php-xml php-zip php-curl php-gd sudo systemctl restart apache2 mysql

Visit http://localhost. Your files go in /var/www/html/.

Option 2 — dnf LAMP (AlmaLinux / Fedora / RHEL)

sudo dnf update -y sudo dnf install -y httpd sudo dnf install -y mariadb-server sudo dnf install -y php php-mysqlnd php-mbstring php-xml php-zip php-curl php-gd sudo systemctl enable --now httpd mariadb sudo systemctl restart httpd mariadb

Visit http://localhost. Files go in /var/www/html/.

Option 3 — XAMPP for Linux

chmod +x xampp-linux-x64-.run sudo ./xampp-linux-x64-.run sudo /opt/lampp/lampp start

Visit http://localhost. Files go in /opt/lampp/htdocs/.

Option 4 — PHP built-in server (no Apache needed)

cd /path/to/your/project php -S localhost:8000

Visit http://localhost:8000. Fastest possible test server. Not for production.

PERMISSIONS: On Linux, /var/www/html is owned by www-data. To edit files as your user: sudo chown -R $USER:$USER /var/www/html. To run PHP scripts from CLI: php yourfile.php.

CROSS-PLATFORM TOOLS (all OS)

Composer — PHP dependency manager

Essential for modern PHP. Works on Windows, macOS, Linux.

# macOS / Linux curl -sS https://getcomposer.org/installer | php sudo mv composer.phar /usr/local/bin/composer # Windows: download Composer-Setup.exe from getcomposer.org

Git — version control

# Ubuntu / Debian sudo apt install -y git # AlmaLinux / Fedora sudo dnf install -y git # macOS (with Homebrew) brew install git # Windows: download from git-scm.com

VS Code — editor with PHP support

Install the PHP Intelephense extension for autocomplete, linting, and debugging.

VERIFY YOUR SERVER WORKS

Create a file called test.php in your web root and put this inside:

<?php phpinfo(); ?>

Visit http://localhost/test.php. If you see the purple PHP info page, your server is running. If you see the raw code, PHP is not being parsed — check that libapache2-mod-php (Linux) or the PHP module (XAMPP) is enabled.

DELETE test.php AFTER. phpinfo() exposes your PHP version, modules, and paths to anyone who can reach the server. Never leave it on a public machine.