Apache HTTP Server Local Development Guide

Install and configure Apache HTTP Server on localhost, default ports 80/8080, local access at http://localhost.


Apache HTTP Server (commonly referred to as Apache or httpd) is one of the most widely used web servers globally. It is open-source, cross-platform, and often combined with PHP and MySQL to form the LAMP stack, serving as a core component for local PHP development.

Default localhost Access

PurposeAddress
Local Sitehttp://localhost
Alternative Porthttp://localhost:8080

It listens on port 80 by default; if occupied, you can change it to 8080 in the configuration.

Installation Methods

  • Linux: sudo apt install apache2 (Debian/Ubuntu) or sudo yum install httpd (RHEL/CentOS)
  • macOS: Comes pre-installed or can be installed via Homebrew with httpd
  • Windows: Install Apache separately or use the built-in version in XAMPP / WAMP

Website Root Directory

SystemCommon Path
Linux (Debian)/var/www/html/
macOS (Homebrew)/usr/local/var/www/
XAMPPC:\xampp\htdocs\

After placing files in the root directory, access them via http://localhost/filename.

Common Commands

# Linux / macOS
sudo apachectl start
sudo apachectl stop
sudo apachectl restart

Frequently Asked Questions

403 Forbidden
Check directory permissions and the DocumentRoot and Directory configurations in httpd.conf.

Port 80 Occupied
Modify Listen 8080 and access via http://localhost:8080.

Configuration Changes Not Taking Effect
Ensure Apache has been restarted and check if the virtual host configuration file was modified correctly.

Summary

Apache is a classic choice for running PHP static/dynamic sites on localhost. Combined with XAMPP, WAMP, or a native installation, you can debug locally using http://localhost.

访客计数:------ Best viewed in Netscape Navigator · 800×600 © LocalHost Run