LFCE 50 ๐ง Web Server โ Apache Installation
Apache HTTP Server, commonly called httpd, is the other major web server in the Linux ecosystem. Where the previous chapters covered Nginx as a high-performance static file server and reverse proxy, Apache is a process-based server with a modular architecture, a long history, and a configuration style built on directives inside <Directory>, <VirtualHost>, and <Location> blocks. The installation is a package manager command on both major distribution families, but the package name, the service name, the configuration layout, and the user account all differ between Debian and RHEL.
The previous chapters covered Nginx installation and configuration. This chapter covers the Apache equivalent: the package names, the directory structure, the service management commands, and the firewall rules that make the default “It works!” page reachable from a remote client. It builds the foundation for the virtual host and module configuration that follows.
Key point: The package name and service name differ by distribution. Debian and Ubuntu use apache2 for both the package and the service. RHEL, Rocky Linux, and Fedora use httpd for both. The configuration directory differs as well: /etc/apache2/ on Debian, /etc/httpd/ on RHEL. The web server user is www-data on Debian and apache on RHEL . The service must be started and enabled explicitly on both families, and the firewall must permit HTTP before a remote client can reach the default page.
Why Apache installation requires distribution-specific attention
The package-and-service naming problem.
The Apache HTTP Server is the same software on every distribution, but the packaging conventions differ. On Debian and Ubuntu, the package is apache2, the service unit is apache2.service, and the main binary is /usr/sbin/apache2. On RHEL and its derivatives, the package is httpd, the service unit is httpd.service, and the main binary is /usr/sbin/httpd . An administrator following a Debian tutorial on a RHEL system will run apt install apache2 and receive a command-not-found error. The service management commands use the correct name per family.
The configuration-layout problem.
Debian and Ubuntu use a modular configuration layout inherited from the apache2 package. The main file is /etc/apache2/apache2.conf, which includes ports.conf, mods-enabled/*, conf-enabled/*, and sites-enabled/*. The a2ensite, a2dissite, a2enmod, and a2dismod helper scripts manage the symlinks between the *-available and *-enabled directories . RHEL uses a simpler layout: the main file is /etc/httpd/conf/httpd.conf, and additional configuration fragments are placed in /etc/httpd/conf.d/ and are included automatically . The same virtual host configuration content works on both, but the file placement and the enablement mechanism differ.
The user-account problem.
The Apache worker processes run as an unprivileged user. On Debian and Ubuntu, that user is www-data; on RHEL and its derivatives, it is apache . The DocumentRoot directory and its files must be readable by this user. A web root that is owned by root with restrictive permissions produces a 403 Forbidden response even though the configuration is correct. The chown command must use the correct user for the distribution.
a. Installing on Debian and Ubuntu
The apache2 package is in the default repositories. The installation is two commands: update the package index, then install the package.
# Update the package index
sudo apt update
# Install Apache
sudo apt install apache2 -y
# Verify the installed version
apache2 -v
# Output: Server version: Apache/2.4.58 (Ubuntu)
The package installs the service, starts it automatically, and configures it to start at boot. The systemctl status apache2 command confirms that it is running. The default web root is /var/www/html, and the default page is served from there .
The apache2ctl configtest command validates the configuration syntax before a reload. It is the Apache equivalent of nginx -t and should be run after every configuration change .
# Validate the configuration
sudo apache2ctl configtest
# Output: Syntax OK
b. Installing on RHEL and its derivatives
The httpd package is in the AppStream repository. The installation command uses dnf or yum, and the service must be started explicitly after installation.
# Install Apache
sudo dnf install httpd -y
# Start the service
sudo systemctl start httpd
# Enable the service at boot
sudo systemctl enable httpd
# Verify the installed version
httpd -v
# Output: Server version: Apache/2.4.57 (Red Hat Enterprise Linux)
The RHEL package does not start the service automatically. The systemctl start httpd command starts it, and systemctl enable httpd configures it to start at boot. The combined form systemctl enable --now httpd performs both operations in one command . The default web root is /var/www/html, the same path as on Debian.
The httpd -t command validates the configuration syntax. It reads the main configuration file and all included files, and reports any syntax errors with the file and line number.
# Validate the configuration
sudo httpd -t
# Output: Syntax OK
c. Opening the firewall and verifying the service
The firewall must permit HTTP traffic before a remote client can reach the default page. The command differs between ufw on Debian and firewalld on RHEL.
# Debian/Ubuntu with ufw
sudo ufw allow 'Apache Full'
sudo ufw status
# RHEL/Rocky with firewalld
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
The ufw allow 'Apache Full' command opens both port 80 and port 443 using the application profile that the apache2 package installs . The firewall-cmd commands open the http and https services permanently, and --reload applies the changes to the running firewall .
Verification has two parts: confirming that the service is listening on port 80, and confirming that a client can retrieve the default page.
# Confirm Apache is listening on port 80
sudo ss -antpl | grep :80
# Output: LISTEN 0 511 *:80 *:* users:(("apache2",pid=...))
# Test locally with curl
curl -I http://localhost
# Output: HTTP/1.1 200 OK
# Server: Apache/2.4.58 (Ubuntu)
The ss command confirms that the Apache process has bound to port 80. The curl -I command retrieves the HTTP headers from the local server and confirms that it returns 200 OK. A browser request to the server’s IP address returns the default “It works!” page or the Apache2 default page .
Complete Example Session
# ============================================
# PART 1: UPDATE THE PACKAGE INDEX (DEBIAN)
# ============================================
sudo apt update
# ============================================
# PART 2: INSTALL APACHE
# ============================================
sudo apt install apache2 -y
# ============================================
# PART 3: VERIFY THE INSTALLED VERSION
# ============================================
apache2 -v
# Output: Server version: Apache/2.4.58 (Ubuntu)
# ============================================
# PART 4: CHECK THE SERVICE STATUS
# ============================================
sudo systemctl status apache2
# Output should show "active (running)"
# ============================================
# PART 5: ENABLE THE SERVICE AT BOOT
# ============================================
sudo systemctl enable apache2
# ============================================
# PART 6: OPEN THE FIREWALL (UFW)
# ============================================
sudo ufw allow 'Apache Full'
sudo ufw status
# Output includes: Apache Full ALLOW Anywhere
# ============================================
# PART 7: CONFIRM THE LISTENING PORT
# ============================================
sudo ss -antpl | grep :80
# Output: LISTEN 0 511 *:80
# ============================================
# PART 8: TEST LOCALLY WITH CURL
# ============================================
curl -I http://localhost
# Output: HTTP/1.1 200 OK
# ============================================
# PART 9: TEST FROM A REMOTE CLIENT
# ============================================
# From another machine on the network:
# curl http://<server-ip>
# The default "It works!" page is returned
# ============================================
# PART 10: INSPECT THE DEFAULT CONFIGURATION
# ============================================
ls -l /etc/apache2/
# Output: apache2.conf, ports.conf, sites-available/, sites-enabled/
cat /etc/apache2/sites-enabled/000-default.conf
# The default virtual host listens on port 80 and serves /var/www/html
The ten parts demonstrate the complete installation and verification workflow: package update, installation, version check, service status, boot enablement, firewall opening, port verification, local test, remote test, and configuration inspection. The critical verification steps are Parts 7 and 8: the service must be listening, and it must return a successful HTTP response.
Quick Reference
Installation Commands
| Distribution | Package | Service | Config Directory |
|---|---|---|---|
| Debian / Ubuntu | apache2 | apache2 | /etc/apache2/ |
| RHEL / Rocky / Fedora | httpd | httpd | /etc/httpd/ |
Firewall Commands
| Firewall | Open HTTP/HTTPS | Apply |
|---|---|---|
| ufw | ufw allow 'Apache Full' | Automatic |
| firewalld | firewall-cmd --permanent --add-service=http | firewall-cmd --reload |
Service Management
| Command | Purpose |
|---|---|
systemctl start apache2 / httpd | Start the service |
systemctl enable apache2 / httpd | Start at boot |
systemctl enable --now apache2 / httpd | Start and enable |
systemctl status apache2 / httpd | Check service state |
systemctl reload apache2 / httpd | Re-read configuration |
Validation Commands
| Command | Distribution | Purpose |
|---|---|---|
apache2ctl configtest | Debian | Validate configuration syntax |
httpd -t | RHEL | Validate configuration syntax |
apache2 -v / httpd -v | Both | Show installed version |
ss -antpl | grep :80 | Both | Confirm listening on port 80 |
Best Practices
โ Do This:
# Use the correct package name for the distribution
apt install apache2 # Debian/Ubuntu # โ
dnf install httpd # RHEL/Rocky # โ
# Enable the service at boot
systemctl enable apache2 # or httpd # โ
# Open the firewall for HTTP and HTTPS
ufw allow 'Apache Full' # or firewall-cmd --add-service=http # โ
# Validate before reloading
apache2ctl configtest # or httpd -t # โ
# Verify the service is listening on port 80
ss -antpl | grep :80 # โ
# Test with curl before testing from a remote client
curl -I http://localhost # โ
โ Don’t Do This:
# Use the Debian package name on RHEL
apt install apache2 # Command not found on RHEL # โ
# Assume the service starts automatically on RHEL
# The httpd package does not start the service # โ
# Forget to reload the firewall after adding the service
firewall-cmd --permanent --add-service=http # Not active # โ
# Test only from the local host
# A local curl succeeds even if the firewall blocks remote access # โ
# Use the wrong web server user for the distribution
chown www-data:www-data /var/www/html # Wrong on RHEL # โ
Common Pitfalls
| Pitfall | Why It Happens | Fix |
|---|---|---|
| Command not found on RHEL | Used apt or apache2 | Use dnf install httpd |
| Service not running after install on RHEL | RHEL package does not auto-start | systemctl start httpd |
| Remote client cannot reach the server | Firewall does not permit HTTP | Open port 80 with ufw or firewall-cmd |
| 403 Forbidden on the default page | Web root permissions wrong | chown to www-data or apache |
| Configuration syntax error | Missing directive or typo | apache2ctl configtest or httpd -t |
| Wrong configuration file edited | Distribution uses different layout | Debian: /etc/apache2/; RHEL: /etc/httpd/ |
Real-World Examples
1. Debian installation
sudo apt update && sudo apt install apache2 -y
2. RHEL installation
sudo dnf install httpd -y
3. Start and enable
sudo systemctl enable --now apache2 # Debian
sudo systemctl enable --now httpd # RHEL
4. Open ufw
sudo ufw allow 'Apache Full'
5. Open firewalld
sudo firewall-cmd --permanent --add-service=http && sudo firewall-cmd --reload
6. Validate configuration
sudo apache2ctl configtest # Debian
sudo httpd -t # RHEL
7. Check listening port
sudo ss -antpl | grep :80
8. Test locally
curl -I http://localhost
9. Check version
apache2 -v # Debian
httpd -v # RHEL
10. Inspect default site
cat /etc/apache2/sites-enabled/000-default.conf # Debian
cat /etc/httpd/conf/httpd.conf # RHEL
Visual
Installation Flow
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ FROM PACKAGE TO REACHABLE WEB SERVER โ
โ โ
โ Step 1: Install โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ apt install apache2 (Debian) โ โ
โ โ dnf install httpd (RHEL) โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ โ
โ โผ โ
โ Step 2: Start โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Debian: automatic โ โ
โ โ RHEL: systemctl start httpd โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ โ
โ โผ โ
โ Step 3: Enable at boot โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ systemctl enable apache2 (Debian) โ โ
โ โ systemctl enable httpd (RHEL) โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ โ
โ โผ โ
โ Step 4: Open firewall โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ ufw allow 'Apache Full' โ โ
โ โ firewall-cmd --add-service=http --permanent โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ โ
โ โผ โ
โ Step 5: Verify โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ ss -antpl | grep :80 โ listening โ โ
โ โ curl -I http://localhost โ 200 OK โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Directory Layout Comparison
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ DEBIAN vs RHEL CONFIGURATION LAYOUT โ
โ โ
โ Debian / Ubuntu: โ
โ /etc/apache2/ โ
โ โโโ apache2.conf โ Main configuration โ
โ โโโ ports.conf โ Listening ports โ
โ โโโ mods-available/ โ All module configs โ
โ โโโ mods-enabled/ โ Active modules (symlinks) โ
โ โโโ sites-available/ โ All site configs โ
โ โโโ sites-enabled/ โ Active sites (symlinks) โ
โ โ
โ RHEL / Rocky: โ
โ /etc/httpd/ โ
โ โโโ conf/ โ
โ โ โโโ httpd.conf โ Main configuration โ
โ โ โโโ conf.d/ โ Additional configs (auto-loaded)โ
โ โโโ conf.modules.d/ โ Module loading configs โ
โ โ
โ Debian uses a2ensite/a2enmod. RHEL places files in conf.d. โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Service and Firewall Comparison
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ DEBIAN/UBUNTU vs RHEL/ROCKY โ
โ โ
โ Service: โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Debian: apache2.service โ โ
โ โ RHEL: httpd.service โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โ Firewall: โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ ufw (Debian): โ โ
โ โ ufw allow 'Apache Full' โ โ
โ โ โ Opens ports 80 and 443 โ โ
โ โ โ โ
โ โ firewalld (RHEL): โ โ
โ โ firewall-cmd --permanent --add-service=http โ โ
โ โ firewall-cmd --permanent --add-service=https โ โ
โ โ firewall-cmd --reload โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Summary
| Item | Value |
|---|---|
| Debian package | apache2 |
| RHEL package | httpd |
| Debian service | apache2.service |
| RHEL service | httpd.service |
| Debian config | /etc/apache2/apache2.conf |
| RHEL config | /etc/httpd/conf/httpd.conf |
| Debian web user | www-data |
| RHEL web user | apache |
| Default web root | /var/www/html |
| Debian firewall | ufw allow 'Apache Full' |
| RHEL firewall | firewall-cmd --add-service=http |
| Validation (Debian) | apache2ctl configtest |
| Validation (RHEL) | httpd -t |
| Listening port | 80 (HTTP), 443 (HTTPS) |
Key takeaways:
- The package and service names differ by distribution. Debian and Ubuntu use
apache2; RHEL and its derivatives usehttpd. The service management commands must use the correct name for the family . - The configuration layout differs. Debian uses
/etc/apache2/withsites-availableandsites-enabledmanaged bya2ensiteanda2dissite. RHEL uses/etc/httpd/withconf.d/for additional configuration fragments . - The web server user differs. Debian runs Apache workers as
www-data; RHEL runs them asapache. TheDocumentRootpermissions must be readable by the correct user . - The service must be started and enabled. Debian starts the service automatically after installation. RHEL does not.
systemctl enable --nowperforms both the start and the boot enablement. - The firewall must permit HTTP.
ufw allow 'Apache Full'opens ports 80 and 443 on Debian.firewall-cmd --add-service=httpand--add-service=httpsopen the same ports on RHEL . - Validate before reloading.
apache2ctl configteston Debian andhttpd -ton RHEL catch syntax errors before the new configuration is applied.
Remember: Apache installation is one package command, but the package name, service name, configuration path, and web server user all depend on the distribution. Debian and Ubuntu use apache2, /etc/apache2/, and www-data. RHEL and Rocky use httpd, /etc/httpd/, and apache. Start and enable the service, open the firewall for HTTP and HTTPS, and verify with ss and curl. The default “It works!” page confirms that the server is reachable. The configuration that followsโvirtual hosts, modules, and TLSโbuilds on this foundation.
Stop using slow, ad-bloated tool sites! ๐คฎ
๐ Search “KandZ Tools” on Google to use many professional utilities for free.
KandZ.me is the ultimate minimalist hub for:
โ
Finance (Mortgage, Interest, Inflation)
โ
Tech (Base64, JSON, Dev Suite, IP)
โ
Health (BMI, BMR, TDEE)
โ
Productivity (Timer, Workspace, QR)
โก๏ธ Fast & Private
๐ No data leaves your device
๐ 100% Free
๐ Use it now: https://tools.kandz.me
๐ Bookmark itโyouโll need it later!