Domain 7System MaintenanceCORE

Managing Apache

Comprehensive guide to configuring, managing, and hardening Apache (httpd) web servers in RHEL, covering installation, document roots, virtual hosts, and reboot persistence.

Domain: Deploy, configure, and maintain systems•Updated: 2026-08-30
#Apache#HTTPD#Web Server#Virtual Hosts#RHCSA#RHEL

Managing Apache

Theory Questions

1. Install the software packages needed for an Apache web server.

  • Command(s):
    dnf install -y httpd

* **Why:** The `httpd` package provides the core Apache HTTP server daemon, baseline modules, and systemd service scripts needed to serve web content on RHEL.
* **Gotchas:** Confusing package names with Debian/Ubuntu (`apache2`); on Enterprise Linux, the package is strictly named `httpd`.
* **Verify:**
```bash
rpm -q httpd

2. Identify the main Apache configuration file.

  • Path / Command:
/etc/httpd/conf/httpd.conf
  • Why: /etc/httpd/conf/httpd.conf is the main configuration file that defines global directives, default listening ports, server roots, and module load rules.
  • Gotchas: Editing /etc/httpd/conf/httpd.conf directly for custom virtual hosts instead of using drop-in files under /etc/httpd/conf.d/*.conf.
  • Verify:
httpd -t

(Checks configuration file syntax; returns Syntax OK)


3. Specify the document root directory in the Apache configuration.

  • Command(s) / Configuration Directive: Inside /etc/httpd/conf/httpd.conf or a drop-in /etc/httpd/conf.d/*.conf:
DocumentRoot "/var/www/html"
  • Why: The DocumentRoot directive specifies the directory tree out of which Apache serves public web documents for incoming HTTP requests.
  • Gotchas: Changing DocumentRoot to a custom directory (e.g., /web) without updating directory permission blocks <Directory "/web"> and SELinux file contexts (httpd_sys_content_t).
  • Verify:
httpd -S | grep "Main DocumentRoot"

4. Define the location where Apache looks for its configuration files (ServerRoot).

  • Path / Configuration Directive:
ServerRoot "/etc/httpd"
  • Why: ServerRoot defines the top-level directory containing the configuration, module, and log subdirectories for the httpd daemon.
  • Gotchas: Modifying ServerRoot to a relative path, which breaks resolution for relative includes like conf.d/*.conf.
  • Verify:
grep "^ServerRoot" /etc/httpd/conf/httpd.conf

5. Identify the directory containing the main Apache configuration file.

  • Path / Command:
/etc/httpd/conf/
  • Why: Stores the primary configuration file (httpd.conf) and default MIME type mappings (magic).
  • Gotchas: Confusing /etc/httpd/conf/ (main config directory) with /etc/httpd/conf.d/ (drop-in modular config directory).
  • Verify:
ls -l /etc/httpd/conf/httpd.conf

6. Identify the directory containing Apache module configuration files.

  • Path / Command:
/etc/httpd/conf.modules.d/
  • Why: Holds configuration drop-in files (*.conf) that load dynamic shared object (.so) modules into Apache using the LoadModule directive.
  • Gotchas: Adding LoadModule directives directly into /etc/httpd/conf/httpd.conf instead of keeping them in /etc/httpd/conf.modules.d/.
  • Verify:
ls -la /etc/httpd/conf.modules.d/

7. Identify the directory where RPMs drop configuration files.

  • Path / Command:
/etc/httpd/conf.d/
  • Why: /etc/httpd/conf.d/ is included automatically by the main httpd.conf file (IncludeOptional conf.d/*.conf). RPM packages (such as php, mod_ssl, and httpd-manual) drop their configurations here.
  • Gotchas: Creating custom config files in /etc/httpd/conf.d/ that omit the required .conf file extension; files without .conf are ignored by default.
  • Verify:
ls -la /etc/httpd/conf.d/

8. Run multiple virtual hosts on the same IP address (name-based virtual hosting).

  • Command(s) / Configuration Example: Create /etc/httpd/conf.d/vhosts.conf:
<VirtualHost *:80>
    ServerName site1.example.com
    DocumentRoot "/var/www/site1"
</VirtualHost>

<VirtualHost *:80>
    ServerName site2.example.com
    DocumentRoot "/var/www/site2"
</VirtualHost>
  • Why: In Apache 2.4, name-based virtual hosting is enabled automatically for all <VirtualHost> blocks sharing an IP address and port; matching occurs via the Host: HTTP request header.
  • Gotchas: Omitting ServerName inside a VirtualHost block. If missing, Apache defaults to the system hostname, routing unexpected traffic to the wrong block.
  • Verify:
httpd -S

9. Start the definition of a virtual host listening on port 80.

  • Configuration Syntax:
<VirtualHost *:80>
  • Why: Declares a virtual host container that responds to requests arriving on port 80 across all available IPv4/IPv6 network interfaces (*).
  • Gotchas: Specifying an explicit IP address (e.g., <VirtualHost 192.168.4.210:80>) inside portable lab configurations that might change IP addressing via DHCP.
  • Verify:
httpd -S | grep ":80"

10. Evaluate statements about virtual hosts, identifying true and false claims.

  • Command(s):
httpd -S
  • Statements Evaluation:

  • True: Apache 2.4 processes virtual host requests using Name-Based hosting by default without requiring a NameVirtualHost directive.

  • True: The first <VirtualHost> entry defined in configuration files acts as the default fallback for unmatched domain requests.

  • False: Virtual host configuration files placed in /etc/httpd/conf.d/ require a manual Include directive in httpd.conf. (Correction: IncludeOptional conf.d/*.conf is built into the default httpd.conf.)

  • Why: Understanding VirtualHost evaluation precedence helps troubleshoot request routing issues.

  • Gotchas: Placing default fallback virtual host definitions at the bottom of a configuration file instead of at the top.

  • Verify:

httpd -S

  • Command(s):
dnf groupinstall -y "Basic Web Server"
  • Why: Installing the "Basic Web Server" environment group pulls in httpd, common modules, documentation, and web administration tooling in a single step.
  • Gotchas: Forgetting quotes around group names containing spaces when executing dnf groupinstall.
  • Verify:
dnf group list installed | grep -i "Basic Web Server"

12. Enable httpd to start automatically at boot.

  • Command(s):
systemctl enable --now httpd
  • Why: systemctl enable --now creates the target symlinks in /etc/systemd/system/multi-user.target.wants/ and immediately launches the service daemon.
  • Gotchas: Running systemctl start httpd without enable. The web server will run immediately but fail to start after a reboot.
  • Verify:
systemctl is-enabled httpd

13. Identify the default location where RPMs drop plug-in configuration files for Apache.

  • Path / Command:
/etc/httpd/conf.d/
  • Why: Packages designed to extend Apache (such as php, mod_ssl, httpd-manual) place modular configuration files (*.conf) into /etc/httpd/conf.d/.
  • Gotchas: Searching /etc/httpd/conf.modules.d/ for application plug-in settings; conf.modules.d/ is reserved for binary module loaders (LoadModule).
  • Verify:
ls -la /etc/httpd/conf.d/

14. Test a web server from a command-line (non-GUI) server.

  • Command(s):
curl http://localhost/
# OR
curl -I [http://127.0.0.1/](http://127.0.0.1/)
  • Why: curl sends HTTP requests to target endpoints directly from the command line, displaying returned raw HTML response bodies or headers (-I).
  • Gotchas: Assuming failure is in Apache when curl fails; always test curl http://localhost/ locally to isolate local daemon issues from network/firewall problems.
  • Verify:
curl -s -o /dev/null -w "%{http_code}\n" http://localhost/

(Returns 200 for successful requests)


15. Identify the default Apache configuration file name.

  • File Name / Command:
httpd.conf
  • Why: Located at /etc/httpd/conf/httpd.conf, this is the main configuration file parsed by the httpd binary on RHEL systems.
  • Gotchas: Searching for apache2.conf (Debian/Ubuntu naming schema).
  • Verify:
ls -l /etc/httpd/conf/httpd.conf

16. Identify the default Apache document root directory.

  • Path / Command:
/var/www/html/
  • Why: Standard filesystem path defined by RHEL default policies for public web content storage.
  • Gotchas: Storing web contents directly under /var/www/ instead of /var/www/html/.
  • Verify:
grep "^DocumentRoot" /etc/httpd/conf/httpd.conf

17. Identify the default file Apache looks for in the document root.

  • File Name / Directive:
index.html
  • Why: Controlled by the DirectoryIndex directive inside /etc/httpd/conf/httpd.conf (e.g., DirectoryIndex index.html).
  • Gotchas: Creating index.htm or default.html without updating the DirectoryIndex directive, resulting in a 403 Forbidden directory listing error.
  • Verify:
grep "DirectoryIndex" /etc/httpd/conf/httpd.conf

18. Check whether the Apache web server is currently running.

  • Command(s):
systemctl status httpd
# OR
systemctl is-active httpd
  • Why: Queries the systemd daemon for active runtime state, process ID, and memory consumption of the httpd.service unit.
  • Gotchas: Running ps aux | grep httpd which shows process execution but does not confirm systemd operational status.
  • Verify:
systemctl is-active httpd

19. Identify the preferred location for storing virtual host configuration files.

  • Path / Command:
/etc/httpd/conf.d/
  • Why: Placing modular files (e.g., /etc/httpd/conf.d/vhost-example.conf) in conf.d/ isolates custom site logic, prevents pollution of httpd.conf, and ensures settings persist across core package updates.
  • Gotchas: Saving files in /etc/httpd/conf.d/ without the .conf extension.
  • Verify:
httpd -S

20. Determine the default ServerRoot directory.

  • Path / Command:
/etc/httpd
  • Why: Acts as the top-level directory root under which Apache finds configuration directories (conf/, conf.d/, conf.modules.d/), module links (modules/), and log links (logs/).
  • Gotchas: Confusing ServerRoot (/etc/httpd) with DocumentRoot (/var/www/html).
  • Verify:
grep "^ServerRoot" /etc/httpd/conf/httpd.conf

Lab Tasks

Apache Practice

Task 1: Install required packages for a basic web server. Ensure the web server process starts automatically at reboot.

  • Command(s):
# 1. Install httpd package:
dnf install -y httpd

# 2. Enable and start httpd service:
systemctl enable --now httpd

# 3. Configure firewalld rules for HTTP traffic:
firewall-cmd --permanent --add-service=http
firewall-cmd --reload
  • Why:

  • dnf install -y httpd: Installs necessary web server binaries.

  • systemctl enable --now httpd: Starts the daemon immediately and registers it to launch automatically at system boot.

  • firewall-cmd: Opens TCP port 80 to allow external web traffic.

  • Gotchas: Forgetting to open Firewalld ports (http/port 80). The web server will run locally but remain unreachable from external network clients.

  • Verify:

systemctl is-enabled httpd
systemctl is-active httpd

Task 2: Use curl to verify the web server presents a default page showing “Welcome to my web server.”

  • Command(s):
# 1. Create index.html in DocumentRoot:
echo "Welcome to my web server" > /var/www/html/index.html

# 2. Ensure correct file permissions:
chmod 644 /var/www/html/index.html

# 3. Verify content using curl:
curl http://localhost/
  • Why: Placing index.html inside /var/www/html/ populates the default document root. Testing via curl http://localhost/ confirms content rendering.
  • Gotchas: File permissions; if index.html lacks read permissions for others (644), Apache will return a 403 Forbidden error.
  • Verify:
curl http://localhost/

(Output displays: Welcome to my web server)


Task 3 & 4: Install httpd-manual documentation package and test access to /manual via command line/browser.

  • Command(s):
# 1. Install httpd-manual package:
dnf install -y httpd-manual

# 2. Reload Apache to process new conf.d/manual.conf configuration:
systemctl reload httpd

# 3. Test access to /manual endpoint:
curl -s http://localhost/manual/ | grep -i "<title>"
  • Why: Installing httpd-manual drops /etc/httpd/conf.d/manual.conf, creating an alias pointing /manual to /usr/share/httpd/manual/. Reloading Apache parses this new configuration file.
  • Gotchas: Forgetting to reload or restart httpd after installing httpd-manual.
  • Verify & Reboot Persistence Test:
# Reboot system to verify persistence across reboots:
reboot

# Post-reboot checks:
systemctl is-active httpd
curl http://localhost/
curl -s http://localhost/manual/ | head -n 10

(Confirms httpd initializes automatically at boot and serves both root index content and manual documentation)