What's changed: Initial version (topic 2.09, subtopics 2.09.1–2.09.4)
3.1Configuring and Managing the Apache HTTP Server
Learn to configure and operate the Apache HTTP Server (httpd/apache2): the httpd.conf file, control via apachectl/apache2ctl, access and error logs, hosting multiple sites with virtual hosts, per-directory overrides via .htaccess, Basic authentication with mod_auth_basic, mod_authz_host, AuthUserFile, AuthGroupFile, and htpasswd, and URL forwarding with Redirect.
The Apache HTTP Server (httpd; apache2 on Debian-based systems) is the longest-running mainstream web server. Its flexibility—hosting multiple sites on one machine and controlling access per directory—is central both in practice and on the LinuC L2 exam.
3.1.1Configuration file and startup control
- The core configuration file is httpd.conf (under /etc/httpd/conf/ or /etc/apache2/ depending on distribution). Directives added or edited here determine how httpd/apache2 behaves.
- Control commands are apachectl (RHEL-family) and apache2ctl (Debian-family), used for syntax checks and restart/reload—checking config validity before applying to production is standard practice.
- Access logs (per-request records) and error logs (startup failures, runtime errors) are the first place to look when troubleshooting—most misconfigurations reveal themselves in the error log.
3.1.2Virtual hosts and Basic authentication
- Virtual hosts (VirtualHost) let one Apache instance host multiple sites (domains), each with its own document root and log destinations.
- Per-directory overrides go in .htaccess, letting you change authentication or behavior for one directory without touching the central config.
- Basic authentication combines mod_auth_basic (the authentication mechanism itself) with mod_authz_host (host/IP-based authorization); AuthUserFile points to the password file location and AuthGroupFile to the group definition file. The htpasswd command creates and updates the password file.
- The Redirect directive forwards requests from one URL path to another—common when a site moves or paths are reorganized.
The most frequent points: .htaccess overrides per directory while httpd.conf sets global behavior, Basic auth = AuthUserFile (built with htpasswd) + AuthGroupFile, mod_auth_basic is the authentication mechanism while mod_authz_host is host/IP-based authorization. apachectl vs apache2ctl is tested as a distribution-naming distinction.
A common real-world request: "protect just the internal admin panel with a password." Place .htaccess in the target directory with AuthType Basic, AuthName "Restricted Area", AuthUserFile /etc/httpd/.htpasswd, and Require valid-user. Build the password file with htpasswd (htpasswd -c /etc/httpd/.htpasswd alice—-c creates a new file, so drop it for the second and later users). To further restrict by IP, add mod_authz_host's Require ip directives for defense in depth, e.g., allowing only the internal network. To host multiple sites on one machine, use virtual hosts to give each domain its own block with an independent document root and log files. To permanently redirect an old URL to a new one, write Redirect permanent /old-path https://example.com/new-path—Redirect handles simple, path-level forwarding. After any change, always run a config test through apachectl/apache2ctl before restarting, then check the error log to confirm the change took effect as intended.
| Element | Role | Key directive/command |
|---|---|---|
| Global config | Server-wide behavior | httpd.conf |
| Directory override | Change one directory only | .htaccess |
| Authentication | Basic auth users/groups | AuthUserFile, AuthGroupFile, htpasswd |
| Multi-site hosting | Independent config per domain | VirtualHost |
Trap: "mod_auth_basic handles host/IP-based control" is wrong—authentication (username/password) is mod_auth_basic; host/IP-based authorization is mod_authz_host. Also, "always pass -c to htpasswd" is wrong: -c is only for creating a new file; using it when adding a second user overwrites the file and deletes existing users.
3.1.3Section summary
- Global config in httpd.conf; per-directory override in .htaccess; control via apachectl/apache2ctl
- Basic auth = AuthUserFile (via htpasswd) + AuthGroupFile + mod_auth_basic; IP control is mod_authz_host; multiple sites via virtual hosts
Sign in to track progress — Log in.
Quick check
(just a quick review)Q1. You need Basic authentication on just an internal admin directory, applying the setting only there without changing the central httpd.conf. How?
Q2. You want to add a second user, bob, to an existing .htpasswd file. Which command is correct?
Q3. After editing an Apache config file, what is the safest way to apply it to production?

