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.
XAMPP is Apache + MariaDB + PHP + Perl in one installer. Free, open source, cross-platform.
C:\xampp. Keep Apache, MySQL, PHP checked.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.
Windows-only alternative to XAMPP. Apache + MySQL + PHP. Slightly lighter, same idea.
http://localhost. Files go in C:\wamp64\www\.Modern, fast, portable. Great for Laravel and WordPress. Free.
Laragon.exe. Click Start All.http://localhost. Files go in C:\laragon\www\.Best if you deploy to Linux servers. Runs a real Ubuntu/AlmaLinux inside Windows.
http://localhost in your Windows browser — WSL2 forwards it automatically.httpd.conf to 8080 and visit http://localhost:8080.
.dmg, drag XAMPP to Applications.http://localhost. Files go in /Applications/XAMPP/htdocs/.Free version: Apache + MySQL + PHP. Pro version adds more. Default port is 8888, not 80.
.dmg, drag MAMP to Applications.http://localhost:8888 automatically. Files go in /Applications/MAMP/htdocs/.If you already use Homebrew, this is the fastest way to serve a single PHP file.
Visit http://localhost:8000. No Apache, no MySQL — just PHP. Perfect for quick tests.
Nginx default web root on Intel Mac: /usr/local/var/www. On Apple Silicon: /opt/homebrew/var/www.
/opt/homebrew on M1/M2/M3/M4 Macs, not /usr/local. Adjust all paths accordingly.
The standard way. Apache + MySQL + PHP, all from the package manager.
Visit http://localhost. Your files go in /var/www/html/.
Visit http://localhost. Files go in /var/www/html/.
Visit http://localhost. Files go in /opt/lampp/htdocs/.
Visit http://localhost:8000. Fastest possible test server. Not for production.
/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.
Essential for modern PHP. Works on Windows, macOS, Linux.
Install the PHP Intelephense extension for autocomplete, linting, and debugging.
Create a file called test.php in your web root and put this inside:
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.
phpinfo() exposes your PHP version, modules, and paths to anyone who can reach the server. Never leave it on a public machine.